On Linux, the command-line is a powerful tool. Once you understand how to use it, it’s possible to accomplish a whole lot of advanced operations really fast. Sadly, new users find the Linux command-line confusing, and don’t know where to start.
In an effort to educate new users on the Linux command-line, we’ve made a list of 25 basic Linux terminal commands to remember. Let’s get started!
ls is the list directory command. In order to use it, launch a terminal window and type the command ls.
The ls command can also be used to reveal hidden files with the “a” command line switch.
cd is how you change directories in the terminal. To swap to a different directory from where the terminal started, do:
It is also possible to go backwards up a directory by using “..”.
To show the current directory in the linux terminal use the pwd command.
If you’d like to create a new folder, use the mkdir command.
To preserve the permissions of the folder to match the permissions of the directory that came before it, use the “p” command line switch.
mkdir -p name-of-new-folder
To delete a file from the command line, use the rm command.
rm can also be used to delete a folder if there are files inside of it by making use of the “rf” command line switch.
rm -rf /path/to/folder
Want to make a copy of a file or folder? Use the cp command.
To copy a file, use cp followed by the location of the file.
Or, to copy a folder, use cp with the “r” command line switch
cp -r /path/to/folder
The mv command can do a lot of things on Linux. It can move files around to different locations, but it can also rename files.
To move a file from one location to another, try the following example.
mv /path/to/file /place/to/put/file|
If you want to move a folder, write the location of the folder followed by the desired location where you’d like to move it.
mv /path/to/folder /place/to/put/folder/
Lastly, to rename a file or folder, cd into the directory of the file/folder you’d like to rename, and then use the mv command, for example:
mv name-of-file new-name-of-file
Or, for a folder, do:
mv name-of-folder new-name-of-folder
The cat command lets you view the contents of files in the terminal. To use cat write the command out followed by the location of the file you’d like to view. For example:
Head lets you view the top 10 lines of a file. To use it, enter the head command followed by the location of the file.
Tail lets you view the bottom 10 lines of a file. To use it, enter the tail command followed by the location of the file.
On Linux, the ping command lets you check the latency between your network and a remote internet or LAN server.
To ping only a few times, use the ping command followed by the “c” command line switch and a number. For example, to ping Google 3 times, do:
ping google.com -c3
To check how long your Linux system has been online, use the uptime command.
The uname command can be used to view your current distribution codename, release number, and even the version of Linux you are using. To use uname, write the command followed by the “a” command line switch.
Using the “a” command line switch prints out all information, so it’s best to use this instead of all other options.
The man command lets you view the instruction manual of any program. To take a look at the manual, run the man command followed by the name of the program. For example, to view the manual of cat, run:
Df is a way to easily view how much space is taken up on the file system(s) on Linux. To use it, write the dfcommand.
To make df more easily readable, use the “h” command line switch. This puts the output in “human readable” mode.
Need to view the space that a directory on your system is taking up? Make use of the du command. For example, to see how big your /home/ folder is, do:
To make the du output more readable, try the ‘hr” command-line switch. This will put the output in “human readable” mode.
du ~/ -hr
With whereis, it’s possible to track down the exact location of an item in the command-line. For example, to find the location of the Firefox binary on your Linux system, run:
Searching for files, programs and folders on the Linux command-line is made easy with locate. To use it, just write out the locate command, followed by a search term.
With the grep command, it’s possible to search for a pattern. A good example use of the grep command is to use it to filter out a specific line of text in a file.
Understand that grep isn’t a command that should ever be run by itself. Instead, it must be combined, like so:
cat text-file.txt | grep 'search term'
Essentially, to use grep to search for patterns, remember this formula:
command command-operations | grep 'search term'
To view current running processes directly from the Linux terminal, make use of the ps command.
Need a more full, detailed report of processes? Run ps with aux.
Sometimes, you need to kill a problem program. To do this, you’ll need to take advantage of the kill command. For example, to close Firefox, do the following.
First, use pidof to find the process number for Firefox.
Then, kill it with the kill command.
Still won’t close? Use the “9” command-line switch.
kill -9 process-id-number
Using the killall command, it’s possible to end all instances of a running program. To use it, run the killall command followed by the name of a program. For example, to kill all running Firefox processes, do:
Need to download a file from the internet through the Linux terminal? Use curl! To start a download, write the curl command followed by the file’s URL, the > symbol and the location you’d like to save it. For example:
curl https://www.download.com/file.zip > ~/Downloads/file.zip
Running out of memory? Check your swap space and free RAM space with the free command.
With chmod, it’s possible to update the permissions of a file or folder.
To update the permissions of a file so everyone on the PC can read, write and execute it, do:
chmod +rwx /location/of/file-or/folder/
To update the permissions so only the owner has access, try:
To update permissions for a specific group or world on the Linux system, run:
The Linux command-line has endless actions and operations to know, and even after getting through this list, you’ll still have a lot more to learn. That said, this list is sure to help beef up your command-line knowledge. Besides, everyone has to start somewhere!