clear
This command cleans up the visible area of the console. It has no options.

$ clear

You can use also thos keyboard shotcuts for cleanning the command line:
CTRL+L - also cleans up the visible area of the console
Ctrl+C - cancel the current command line, which implies clear all the current line no matter where the cursor is.
Ctrl+U - clear all the current line from the end to the beginning only if the cursor is at the end of the line.
Ctrl+K - clear all the current line from the beginning to the end only if the cursor is at the beginning of the line.

history
The command stands for History (Event) Record, it prints the history of long list of executed commands in terminal. Ypu can press “Ctrl + R” to search for already executed commands which lets your command to be completed with auto completion feature.

$ history

whereis       
Show where the binary, source and manual page files are for a command.

Example 1. Locate binaries and manual pages for the ls command.
$ whereis ls


which
Show only the where the binary for a command.

Example 2. Locate the binary for the command grep.
$ which grep


chmod
Make a file executable and runnable by any user. If you have an executable file, you have to mark it as executable first.

Example 3. Make the file script3.sh executable.
$ chmod a+x script3.sh

Example 4. Run the script3.sh executable file.
$ ./script3.sh


du
View the space used by files and folders. Oftten we use to check the space used by our folders and files. Usually du command is used with -sh options which mean:
s - display only a total for each argument (summarize);
h - display in human readable format.

Example 5. What is the size of the file progr1.cpp
$ du -sh progr1.cpp

Example 6. Check the size of all .cpp files from the current directory.
$ du -sh *.cpp

Example 7. What is the size of the folder Documents.
$ du -sh Documents/
12K    Documents


free
The command free displays information about RAM and swap space usage, showing the total and the used amount in both categories. you can use this options with the free command:
-b        Output in bytes
-k        Output in kilobytes
-m        Output in megabytes

Example 8. Display information about RAM and swap usage in megabytes.
$ free -m


date
This simple command displays the current system time.

Example 9. Show the current date and time.
$ date


top
This command provides a quick overview of the currently running processes. Press q to exit the program.

Example 10. Show currently running processes.
$ top
Press q to exit.

ps
If run without any options, this command displays a table of all your own programs or processes — those you started. Usually this command is executed with the options aux, which displays a detailed list of all processes, independent of the owner.

In the 1.1.3 section were explained what are processes ans were given a few examples with the necessary explanation. In this section, when you are already connected to the shell terminal, you can practise by yourself those commands.

Example 11. Display my own programs or processes.
$ ps

Example 12. Display a full list of processes.
$ ps ax

Example 13. Display detailed information about the processes.
$ ps aux
where
    PID    - process identity number
    CPU    - central procecessing unit time
    SIZE   - size of text+data+stack
    RSS    - kilobytes of program in memory
    TTY    - controling terminal (teletype)
    STAT   - status of the process:
       S  sleeping
       T  stopped
       R  running (or ready to run)
       Z  zombie

Example 14. Display the processes of the user apache.
$ ps -u apache

Example 15. Search processes with the name sshd.
$ ps -C sshd


kill
Unfortunately, sometimes a program cannot be terminated in the normal way. However, in most cases, you should still be able to stop such a runaway program by executing the kill command, specifying the respective process ID (see top and ps).

kill sends a TERM signal that instructs the program to shut itself down. If this does not help, the following parameter can be used:
-9        Sends a KILL signal instead of a TERM signal, with which the process really is annihilated by the operating system. This brings the specific processes to an end in almost all cases.

Example 16. Kill the process with the PID 92368.
$ kill -9 92368


killall
This command is similar to kill, but uses the process name (instead of the process ID) as an argument, causing all processes with that name to be killed.

Example 17. Kill the process of the firefox browser.
$ killall firefox

Ultima modificare: marți, 2 mai 2023, 17:11