💾 Archived View for yujiri.xyz › software › guide › commands.gmi captured on 2023-12-28 at 15:38:38. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2023-09-08)
🚧 View Differences
-=-=-=-=-=-=-
yujiri.xyz
Software
Learn programming for good instead of profit
Linux terminal command reference
This page is meant to be read after the Ubuntu command-line tutorial.
Ubuntu command-line tutorial
This is far from all the commands you'll likely have installed on a Linux system, but these are the most important ones. Also, depending on your distribution, some of them might not be preinstalled, so if you try one and it says command not found, that's probably why.
I'll sort the commands within each category from most to least important.
Basic filesystem usage
- cd - change directory. Equivalent to clicking on a folder in a graphical file explorer.
- ls - list the files in the current directory, or the specified directories.
- cat - show the contents of the named file(s) in the terminal window. (Its name is short for *concatenate*, since if you pass it more than one file, it concatenates them.)
- mv - move/rename files (those are actually the same thing).
- nano - An easy-to-use terminal-based text editor that's preinstalled on most Linux distributions. It shows help on the bottom by default.
- pwd - print working directory. Shows the directory you're in (although your shell may show this automatically in the prompt).
- ln - create links (called shortcuts on Windows).
- mkdir - make a directory.
Getting help
- man - "manual". Shows the manual page for the argument you pass it (so `man rm` will get you the manual page on the `rm` command). (And yes there's a manual page on `man`.)
More advanced filesystem usage
- stat - display information about a file.
- chmod - "change mode". Changes file permissions.
- locate - Search the hard drive for a filename containing the given text. Since it uses a cached database, it can search the entire hard drive almost instantly, but the downside is that its database can get out of date. Your distribution may have it configured to update once a week or once a day (you can change that).
- touch - Change a file's access and modification timestamps (creates the file if it doesn't exist).
- file - determine the type of content in a file, for example, whether it's an image, audio, or zip archive.
- find - print the paths of all files in the specified directory and below it. Has many options; for example passing `-type f -name foo` will print only regular files named foo. This type of thing is it's primary use, hence the name of the command.
- du - "disk usage". Show the size of a file or directory.
Text files
- less - like `cat`, but lets you scroll through the output instead of printing it all at once. Useful for large files. You scroll with the up and down arrows (or the page up and page down keys), and might have to press q to get out of it.
The story behind this command's name is that first there was `more`, which did this job and was called so because it lets you see *more* than your screen can fit, and then somebody wanted to make a better version of it and called it *less*. Nowadays, `less` has basically replaced `more`.
- head - show the beginning of a file.
- tail - show the end of a file.
- grep - search through files (or stdin if no files are specified), printing only lines that match a specified regular expression. (`fgrep` is a version that interprets the text to search for literally instead of as a regular expression).
Regular expressions
- wc - "word count". Print the number of words, bytes, and lines in a file.
- diff - show the differences between two files.
Shell utilities
- bg, fg - Move a job to the background/foreground.
- which - find the executable for a command. `which ls` probably shows `/bin/ls`, for example.
- disown - Disassociate a process from your shell session, so that it won't die when your shell exits and your shell won't wait for it.
Process management
- ps - "processes". show a list of running processes and their Process IDs. Often used with `grep` to find the PID of a particular process. `ps -ax | grep firefox` is an easy way to find out what Firefox's PID is. Has many complex flags.
- pgrep - an easier way of finding a process's ID by its command name, but it doesn't show any other information.
- kill - send a signal to a process, the TERM signal by default.
- killall - kill all processes with the given name. Useful as a shortcut for killing a process without having to first find out its PID.
Monitoring
- top - "table of processes". Monitor running processes and resource usage.
- ss - get information about open network connections. (This is a modern replacement for a command called 'netstat'.)
Timed command execution
- crontab - set commands to run at regular intervals, such as every day, every hour, et cetera. This command is very useful but it requires understanding the format of the crontab files. The crontab(5) manual page has the needed information.
- at - schedule a command to run just once at a specified time in the future.
System administration
- date - get or set the system time.
- uname - get information about the system. `uname -a` is the usual form to get more information. You should always include the output of this command when asking for help with Linux.
- dmesg - print the diagnostic messages printed at startup.
Hardware and filesystem stuff
- lspci - get information about connected PCI devices.
https://en.wikipedia.org/wiki/Conventional_PCI
- mount - mount a device, making its contents accessible at a directory you specify (depending on your system, you might have to do this when you connect a flash drive, or it might be done automatically.)
- umount - unmount (pass it the place you mounted it at, not the name of the device).
- df - "disk free". Show the used and available space of your disk (`-h` flag useful to show sizes in a human-readable way).
Networking - diagnostics
- ip - The main command-line program for internet configuration. It has subcommands, like `ip address` to show the address assigned to each of your network interfaces.
- ping - Users coming from Windows or Mac might already be familiar with this command. It sends a meaningless message to another machine, just to test that it can be reached. One of the most commonly used network troubleshooting tools.
- traceroute - Show the path across the internet from your machine to the destination.
- host - Do a DNS lookup (discover the IP address of a domain name).
- tcpdump - Watch a network interface and dump all the packets it receives. Despite the name, not limited to TCP.
Networking - use
- ssh - "Secure SHell". Log into a machine remotely.
- scp - "secure copy". Copy files between machines (it uses SSH).
- nc - "netcat". Send low-level network traffic. Useful for learning about how the internet works or debugging websites and network services.
Dealing with compressed files
If something has a `.zip` extension, the command to unzip it should be `unzip`. If `.gz`, it's `gunzip`. If `.tar`, `tar xf filename` (the `xf` stands for "extract file").
User account management
- su - "switch user". Open a shell as another user to run commands with their credentials. Most commonly used to switch to root. You probably have `sudo` installed, which is an easier way to execute a single command as root without opening a new shell.
- chsh - "change shell", although it does more than change an account's default shell. This command opens an editor (probably `vi` by default) and lets you use that to change any of the user information stored in `/etc/passwd`.
- passwd - change a user's password.
- id - find out what user and group IDs a user has (yourself by default).