12 Useful Linux Commands for New User | Tips & Tricks
Using the command line on a Linux computer can afford you the ability to navigate faster than using a graphical interface, as well as programmatically control what’s on your system. The following are basic commands to navigate and find what you need on most systems. When using a *nix based system, these commands will allow you to navigate the system efficiently and effectively.
man
Google will always be a useful tool, but if you are not connected to the Internet, or if you want to quickly get to the information, the man
command will serve you best. The man
command, short for manual page, will give you the software documentation for a command.
To read the manual for any command, type man command
in the terminal.
For example, man man
will give you the man page for the man command.
Alternatively, if you are familiar with the full documentation, but want a shortened version, most commands allow for the --help
argument, which will give you quick information.
Another usage of man
is to find a command that does what you need. If you need, for example, a command to sort text in a file, you can use the -k
argument, followed by a string of what you are looking for. This will search all descriptions of the commands that match. If you want to search for a specific phrase, include your search argument in quotes.
tail
The tail
command will output the last few lines of a file (by default, the last ten lines). This is especially helpful when viewing log files as the messages are generally appended to the end of a file.
head
Opposite of the tail
command is the head
command. Appropriately named, this command will return the first few lines of a file (by default, the first ten lines). Similar to the tail
command, head
can be useful in situations where you need to pipe information to another command, or when getting the latest information from a file, if the information is prepended. Head can be a quick way to view the beginning a file, such as a script with header comments.
cat
The cat
command concatenates files and sends that information to the standard output. It allows multiple files as arguments but can display one file just as well. This is useful for reading a file in a quick way or piping the information to another command.
rm
The rm
(remove) command deletes files and directories. If you are unsure of what you are deleting, you can do so interactively. The command does not remove directories without adding the force argument -f
, so it could save you if you have directories or lower files you don’t necessarily want removed. Alternatively, you can use the rmdir
command to specifically remove empty directories.
pwd
The pwd
command prints the working directory – the directory where you are currently. This can be useful if you are working with a remote directory and are unsure where you are with regards to the directory where you need to be.
cd
The cd
command changes the current directory (which can be found with the above command, pwd
). You can change to any directory available to you, based on the permissions on that directory. To quickly change to your home directory, you can use the “~/” argument as the directory.
clear
The clear
command clears the screen in your view and allows you to start back with just the prompt. In some cases you can also use Ctrl + l, which will perform the same task.
ls
The ls
command will list the contents in a directory. By default, entries are sorted alphabetically. There are numerous arguments that can be used with this command, and like many others, the results given can be sent to another command.
mkdir
The mkdir
command makes a directory based on the arguments you supply. This is exceptionally helpful if you are making numerous directories with a script, as you can send a verbose response for each directory created.
cp
The cp
command copies files and directories to locations where you have access. You are able to copy multiple sources at once, as well as utilize regular expressions to move files or folders.
The simplest move would be to copy one file to another location.
mv
The command mv
will move, or rename, files or directories. It is akin to the cut and paste action in your desktop. If you are currently in a directory and use the mv
command, it will rename the item to the destination argument (typically the last argument). If you use mv
to another directory, the item will be moved there. Similar to cp
, multiple sources can be added as the argument, with the last argument being the final location.
There are a myriad of other commands that are useful in day-to-day use of Linux, including grep
, sed
, awk
, etc. However, for basic usage and navigation of a Linux system, these are core foundations. Ultimately, the system you use will define what you use and need the most.