Linux has a ton of commands, but most people only use a fraction of them. Here are some of the most used Linux commands to use in the terminal.
First, we'll cover some tips that will make the command line easier to use:
- Use tab for autocompletion. After you start typing something in the Linux terminal, hit tab and it will suggest possible options that start with the string you have typed so far.
ctrl+r search_termto search commands you have previously used.
- Quickly move to the beginning or end of a line with
- Reuse the previous command in the present command with
- You can run multiple commands in a single line by separating commands with a
It's time to learn the common Linux commands. You can get more information about any of these commands by using the
man command. This will bring up the manual page for a command. For example, if you type
man cat into a linux terminal, you will get more information about the
List directory contents.
ls /applications will display all the files and folders stored in the applications folder.
Change to a directory.
Example: Change from the current directory to /usr/local with
Rename or move file(s) or directories.
Example: the command
mv todo.txt /home/qlarson/Documents would move "todo.txt" to the "Documents" directory.
Create a new directory.
mkdir freecodecamp will make a directory named "freecodecamp".
Delete empty directories.
Create an empty file with the specified name.
Remove file(s) and/or directories.
rm todo.txt will delete the file.
Locate a specific file.
locate -i vacuum*mop command will search for any file that contains the word "vacuum" and "mop". The
-i makes the search case-insensitive.
Clear a command line screen/window for a fresh start.
Copy files and directories.
Example: the command
cp todo.txt /home/qlarson/Documents would create a copy of "todo.txt" to the "Documents" directory.
Create an alias for Linux commands.
alias search=grep will allow you to use
search instead of
Display the contents of a file on the screen.
cat todo.txt will show the text of "todo.txt" on the screen.
Change who owns a file.
chown qlarson todo.txt will make "qlarson" the owner of "todo.txt".
Change a file’s permissions.
chmod 777 todo.txt will make "todo.txt" readable, writable, and executable by everyone. The digits in "777" specify the permissions for user, group, and others, in that order.
Perform tasks that require administrative or root permissions.
sudo passwd quincy to change the password of user "quincy".
"Sudo make me a sandwich."
Search for files matching a provided pattern. This command is for searching file(s) and folder(s) using filters such as name, size, access time, and modification time.
find /home/ -name todo.txt will search for a file named "todo.txt" within the home directory and its subdirectories.
Search files or output for a particular string or expression. This command searches for lines containing a specified pattern and, by default, writes them to the standard output.
grep run todo.txt will search for the word "run" in the "todo.txt" file. Lines that contain "run" will be displayed.
Display or set the system date and time.
Display report on the system’s disk space usage.
Show how much space each file takes up. This will show the size in disk block numbers. If you want to see it in bytes, kilobytes, and megabytes, add the
-h argument like this:
Determine the type of a file.
file todo.txt would likely show the type of "ASCII text".
Shows the command history.
Stop a process.
Example: Stop a process with a PID of 485 using the command
kill 485. Use the
ps command (below) to determine the PID of a process.
View the contents of a file one page at a time.
less todo.txt will display the contents of "todo.txt".
Display a list of the currently running processes. This can be used to determine PIDs needed to
Display the pathname for the current directory. "print working directory"
Remotely log in to another Linux machine, over the network.
ssh email@example.com will login to 22.214.171.124 using the username "quincy".
tail - Display the last 10 lines of a file. See fewer or more lines by using the -n (number) option.
tail -n 5 todo.txt will display the last 5 lines of "todo.txt".
Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz).
Displays the resources being used on your system, similar to the task manager in Windows.