Linux terminal command reference
I'm aiming this article mostly at absolute beginners to Linux, as I feel the guidance resources available for a Windows user switching to Linux on their own are woefully inadequate right now. It's meant to be read after the Ubuntu command-line tutorial.
Ubuntu command-line tutorial
There are lots of places that list "the basic" terminal commands, but I've never seen one of those references that lists enough of them to really show how awesome the terminal is to someone who hasn't seen it. 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 Windows File Explorer.
- ls - list the files in the current directory, or the specified directories if any.
- cat - show the contents of the named file(s) in the terminal window. (Its etymology is that it's 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 text editor that's preinstalled on most Linux distributions. It shows help on the bottom by default, so it's good for newcomers.
- 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 - create a directory.
- 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`.)
- info - a younger and Linux-specific alternative to `man`. A bit more sophisticated (info pages can link to each other) but still a primitive-feeling terminal program.
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 argument. 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 (but 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 (this can sometimes even detect programming languages and stuff).
- 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.
- 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.
I believe 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. `tail` has a particularly useful flag `-f` that makes it keep following the file and print out any new data that gets appended to it. That's mostly useful for log files, but that's not something new Unix users are expected to deal with.
- grep - search through files (or stdin if no files are specified), printing only lines that match a certain regular expression. (`fgrep` is a version that interprets the text to search for literally instead of as a regular expression).
- wc - "word count". Print the number of words, bytes, and lines in a file.
- diff - show the differences between two files.
- bg, fg - Move a job to the background/foreground.
- which - find the location of the executable for a command. `which ls` should show `/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.
- ps - "processes", or "process status". 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.
- top - "table of processes". Monitor running processes and resource usage.
- netstat - get information about open network connections. (`netstat -r` shows the routing table.)
- ss (Linux only) - alternative to 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.
- 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 (pciconf on FreeBSD systems) - get information about connected PCI devices.
- mount - "mount" a device, making its contents accessible at a directory you specify (depending on your system, you may have to do this when you connect a flash drive.)
- umount - unmount (pass it the place you mounted it at, not the name of the device).
- df - "disk free". Show the used and availablee space of your disk (`-h` flag useful to show sizes in a **h**uman-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.
- drill - 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. Outmoded by `ncat` (not built-in).
- cu - "call Unix". Used to connect over serial cables. This is by far the most obscure thing I list, but I've needed it to connect to a home-assembled BSD router when its internet wasn't working.
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).
subscribe via RSS