Linux terminal commands
You probably already know some Linux terminal commands, know how to work with files, directories and perform editing such as: cd, ls, pwd, cat. But this overview makes everything as specific as possible in order to anticipate common questions.
Basics in Linux Terminal
The following commands will give you a better understanding of the system:
- id – if you want to get information concerning your account;
- w – to find out who is currently logged in (-f – to find out where you’re logged in from);
- lsblk – if you want to open a list of block storage devices;
- lscpu – displays information about the processors;
- lstopo – provides access to the topology of the hardware display software (hwloc, hwloc-gui packages are required);
- free – shows the amount of free and already used memory (use also free -g);
- lsb_release -a – if you want to get information about data distribution;
- Note for PS0: use Ctrl+C to deactivate irrelevant commands. As for PS1: some commands may not be available. To check which ones, type which .
Working with processes
Start by creating a list of the processes by name, process ID number, etc. (the commonly used sign of aux status).
Keep in mind that POSIX, GNU and BSD implementations of software threads, and that they differ in function and usage. The above implementations differ in different options: POSIX (-), GNU (-), BSD (no dashes).
The process indicators in this system are: top, htop, atop.
Lower the priority of a process using nice. For example like this:
- nice -n 19 tar cvzf archive.tgz large_dir
- To kill a process type kill . This command is used to terminate zombie processes or to end hung sessions.
The following are the Linux terminal commands which will save you the trouble:
- man nano – this command gives access to the help pages, organized by sections. That is one page per section. For example: 5 passwd #5th section;
- wget –help is a very handy command that will give you a quick help on the syntax;
- info curl – allows you to get information about the command (in this case curl);
- /usr/share/doc – use in your browser. In case of a problem, keep in mind that README files usually contain information and examples of commands. You can view them with your browser.
Working with files
You will need the following commands for files of various types and sizes:
- cat for relatively short files:
- cat – for relatively short files;
- less – reads text in small pieces, not all of it:
- less /etc/ntp.conf;
- more – for long files;
- tail -f – used to view the growing file in the interactive code window.
What can you do with binary files? There are not really many options:
- strings – the command will output the file’s print-ready strings;
- od – allows you to print the file in octal format;
- cmp – allows you to compare files byte-for-by-byte.
If you need to compare text files with each other, type the following commands:
- comm – the sorted files will be line by line;
- diff – allows you to tell the difference line by line. This command is the most commonly used because of its rich set of options.
Internet at the command line
Use the following commands when working in a Linux terminal with Internet resources:
- curl – usually used for downloads from the Internet:
- curl -O http://www.gutenberg.org/files/4300/4300-0.txt
- curl ifconfig.me #quickly finds your ID
- wget – similar command:
- wget http://www.gutenberg.org/files/4300/4300-0.txt
- wget https://kubernetespodcast.com/episodes/KPfGep{001..062}.mp3
- lynx allows you to use a fairly user-friendly text browser.
Convenient in this case means that you:
- can finally get rid of the constantly popping up ad windows;
- solve the problem of slow/hang-up internet, for example: lynx text.npr.org;
- be able to access local html pages, such as those found with /usr/share/doc;
- w3m and links are additional text browsers: w3m lite.cnn.com.