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.
sudo
We can run a command as another user with the sudo
command.
It lets us run commands as root.
For instance, we can run:
sudo nano /etc/hosts
to open the /etc/hosts
file with nano
as root.
We can also run sudo -i
to start a shell as root.
And we can run as another user with the -u
flag:
sudo -u bob ls /users/bob
We run ls
as bob
.
su
The su
command lets us switch the shell to another user.
For instance, we run:
su bob
to run the shell as bob
.
When we’re done, we type exit
to return to our own shell.
clear
clear
lets us clear the screen of the terminal.
ctrl+l is a shortcut to clear the screen.
clear -x
clears the screen but lets us go back to see previous work by scrolling up.
who
The who
command lets us display the users logged into the system.
Each shell opened will be listed.
We can see the terminal used and the time and day the session was started.
The -aH
flags tell who
to display more info like idle time and process ID of the terminal.
who am i
liust the current terminal session’s details.
whoami
The whoami
command print the current user name.
which
which
shows where the command is stored.
For instance, we run which ls
to see where ls
is stored.
type
The type
command lets us determine the type of command we’re running.
A command can be one of 4 types:
- an executable
- a shell built-in program
- a shell function
- an alias
fg
The fg
common put a job that’s running in the background into the foreground.
We can get the job ID of jobs with the job
command.
And we can use the job ID as the argument of fg
.
So we run:
fg 2
to put job with ID 2 into the foreground.
bg
bg
resumes a job that’s been suspended.
We can get the job ID of jobs with the job
command.
And we can use the job ID as the argument of fg
.
So we run:
fg 2
to resume the job with ID 2.
jobs
jobs
lets us list the status of the jobs we started.
alias
The alias
command lets us create a shortcut to another command.
For instance, we can run:
alias ll='ls -al'
to create the alias ll
to run the ls -al
command.
killall
The killall
command lets us send signals to multiple processes currently running.
Then general syntax is:
killall <name>
where name
is the name of the program.
Conclusion
We can run commands to manage jobs and process with various Linux commands.
Top comments (0)