Check out my books on Amazon at https://www.amazon.com/John-Au-Yeung/e/B08FT5NT62
Subscribe to my email list now at http://jauyeung.net/subscribe/
Linux is an operating system that many developers will use.
Therefore, it’s a good idea to learn some Linux commands.
In this article, we’ll look at some useful Linux commands we should know.
kill
The kill
command lets us send signals to a process.
The general format is:
kill <PID>
where PID
is the process ID.
We can send signals like:
kill -HUP <PID>
kill -INT <PID>
kill -KILL <PID>
kill -TERM <PID>
kill -CONT <PID>
kill -STOP <PID>
HUP
means hang up. It’s sent when a terminal window that started a process is closed before terminating it.
INT
means interrupt. It sends the signal when we press ctrl+c.
KILL
is sent to the OS kernel to stop and terminate the process.
TERM
means terminate. The process that receives it will terminate.
CONT
means continue. It lets us resume a stopped process.
STOP
is sent to the OS kernel instead of the process, which stops but doesn’t terminate the process.
We can also use a number to replace these signals. 1 is HUP
, 2 is INT
, 9 is KILL
, 15 is TERM
, 18 is CONT
.
top
The top
command lets us list processes running in real time.
We can quit top
with ctrl+c.
And we can sort processes by the amount of memory used by running:
top -o mem
echo
echo
lets us print arguments passed to it.
For instance, we run:
echo "hello" >> output.txt
to put hello
into the output.txt
file.
Also, we can interpolate environment variables in the string:
echo "path=$PATH"
We have to escape special characters like $
in the command.
We can echo the files in the current folder with:”
echo *
And we can echo the files that start with a
with:
echo a*
We can print the home folder path with:
echo ~
We can also print the results of a command with $()
like:
echo $(ls)
ps
The ps
command lets us list the processes currently running in the system.
We can list all processes with the ps ax
command.
a
is used to list other users' processes.
x
shows processes not linked to any terminal.
ps axww
continues the command listing on a new line instead of truncating it.
The output has the PID
which is the process ID, TT
tells us the terminal ID used.
STAT
tells us the state of the process.
I
means the process is idle. R
is a runnable process. S
is a process that’s sleeping for less than 20 seconds.
T
is a stopped process, U
is a process in uninterruptable wait and Z
is a dead process.
+
means the process is in the foreground. s
means the process is a session leader.
ln
ln
lets us create links in the filesystem.
The syntax of the command is:
ln <original> <link>
For instance, we run
ln foo.txt newfoo.txt
to create the newfoo.txt
link to the foo.txt
file.
Links are indistinguishable from a regular file from the user’s perspective.
Conclusion
We can manage processes and create symbolic links with Linux commands.
Top comments (0)