The Command Line is quite a powerful tool for Linux, and once you get the hang of it, you can do things on the system a lot faster although controlling things from the be pretty intimidating.
So, what you can do to be more efficient, is to do it regularly. And to get started, here are some of the most common commands you should know.
I strongly suggest you recommend you bookmark this page or print it out for reference.
ls brings up the list of all the folders and files in the directory you are in. Simply launch the terminal and type the command ls.
The ls command can also be used to reveal hidden files with the “a” command line switch.
cd command is used to change directories. Simply type the command, followed by the directory path. like path/abc/efg
You can also go backwards up a directory by using “..”
To show the current directory in the linux terminal use the pwd command.
This helps you create a new folder, in the directory you are in.
You can use ‘rm’ command to delete a file.
Similarly, you can use the ‘rf’ command to delete the folder along with the files it is containing.
rm -rf /path/to/folder
‘cp’ is used for making a copy of a file or a folder.
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|
The cat command will let 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.
Using the man command, you can 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 df command.
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
Using whereis, you can track down the exact location of an item in the command-line. To find the location of the Firefox binary on your Linux system, you can 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, you can 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 Chrome processes, type this:
You can use curl to download a file from the Internet. 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.
Change the permissions of a file, so everyone on the PC can read, write and execute it, type this:
chmod +rwx /location/of/file-or/folder/
For updating the permissions, so only the owner has access,use this:
To update permissions for a specific group, or the world on the Linux system, run:
So, these are few of the commonly used commands in the Linux command line too. Surely, it does help the normal users to access the system using a visual interface, but the command line has its own base, and if you are looking to learn, this article can be a good start.