15 most basic Linux commands every system admin and DevOps must know
Almost everyone who sees a black screen and commands running on it seems to have a different kind of feeling towards how that works. But being in IT, most people know it’s nothing but a terminal. Terminal is so powerful that without using GUI, with set of commands you can do wonders in your system or servers. First step towards learning DevOps or being a system admin, you should start learning commands that run on terminal and have proeficiency in that. To do, here’s list of 15 such basic commands which will help you get started with the Linux command line better.
1. ls
ls
command is used to list files and directories in the current path
along with ls
- use
-a
to see hidden files and folders - use
-l
to see file permission and dates of creation for files and directories - use
-h
to see files and directory size in human-readable form like GB and MB
$ ls -lah
total 16K
drwxr-xr-x 4 root root 4.0K Jul 18 03:11 .
drwx------ 18 root root 4.0K Jul 17 19:18 ..
-rw-r--r-- 1 root root 0 Jul 18 03:11 identicalcloud-file1
-rw-r--r-- 1 root root 0 Jul 18 03:11 identicalcloud-file2
drwxr-xr-x 3 root root 4.0K Apr 11 14:36 java
drwxr-xr-x 4 root root 4.0K Mar 20 15:34 nodejs
to list files and folders of a particular directory add the path of that directory
$ ls -lah /home
total 12K
drwxr-xr-x 3 root root 4.0K Jan 23 17:44 .
drwxr-xr-x 23 root root 4.0K Jun 24 06:15 ..
drwxr-xr-x 7 ubuntu ubuntu 4.0K Jul 12 13:14 ubuntu
2. pwd
pwd
command will give you a path of the current working directory
$pwd
/home/ubuntu
3. mkdir
mkdir
command is used to create folder/directory
$mkdir IdenticalCloud-dir1
- it will create IdenticalCloud-dir1 folder in current directory
$mkdir /home/ubuntu/IdenticalCloud-dir2
- it will create IdenticalCloud-dir2 folder in home/ubuntu directory
$mkdir -p /var/www/html
- this will create parent folder if they doesn't exist, for example if www folder doesn't exist, it will create and then create html under it
4. touch
touch
command is used to create an empty file
$touch identicalcloud-file1
create empty file named as identicalcloud-file1 in current folder
$touch /home/ubuntu/identicalcloud-file2
create empty file named as identicalcloud-file2 in /home/ubuntu directory
5. cd
cd
command is used to go to a particular directory
you can use cd
with relative or absolute paths like below
$cd java
- it will move to java directory which is in current directory
$cd /home/ubuntu
- it will go to absolute path for ubuntu home directory
$cd ..
- will come out of directory at one level
$cd ../..
- wil come out of 2 directories
$cd
- will move you to root/home directory of current user
6. rm
rm
command is used to delete folder/directory
$rm identicalcloud-file1
- it will delete identicalcloud-file1 named file in current directory
$rm /home/ubuntu/identicalcloud-file2
- it will delete identicalcloud-file2 named file in home/ubuntu directory
$rm -R /home/ubuntu/IdenticalCloud-dir1
- this will delete IdenticalCloud-dir1 folder's all files and folders recursively, so handle this command with care.
7. rmdir
rmdir
command is used to delete folder/directory
$rmdir IdenticalCloud-dir1
- it will delete temp folder in current directory, to use this command IdenticalCloud-dir1 should be empty
$rmdir /home/ubuntu/IdenticalCloud-dir2
- it will delete IdenticalCloud-dir2 folder in home/ubuntu directory
8. export
export
command is used to set variable values in the system
$export var1="Hello World!"
- it will set variable var1's value to "Hello World!" string
9. echo
echo
command is used to print data, be it variable or string or any other data type
$echo "IdenticalCloud"
IdenticalCloud
- it will print above data
$echo $var1
Hello World!
- it will print variable var1's stored value
10. date
date
command is used to print the system’s date in the required format
$date
Sat Jul 17 18:37:13 UTC 2021
with the date command you can use other arguments to get a date in a specific format. For example
+%D
print date as mm/dd/yy format.+%d
print the day of the month (01 to 31).+%a
print the short name for weekdays (Sun to Sat).+%A
print full weekdays (Sunday to Saturday).+%h
print short month name (Jan to Dec).+%B
print full month name(January to December).+%m
print the month of year (01 to 12).+%y
print last two digits of the year(00 to 99).+%Y
print year in four-digit number.+%T
print the time in 24 hour format as HH:MM:SS.+%H
print the hour.+%M
print the minute.+%S
print the seconds.
$date +%D-%a
07/17/21-Sat
11. cp
cp
command is used to copy files and directories from one loation to another
$cp identicalcloud-file1 identicalcloud-file3
- it will copy identicalcloud-file1 file to identicalcloud-file3 file
$cp -R IdenticalCloud-dir1/ IdenticalCloud-dir3/
- it will copy all files and folders of IdenticalCloud-dir1 directory recusrively to IdenticalCloud-dir3 directory
12. mv
mv
command is used to move files and directories from one loation to another
$mv identicalcloud-file1 identicalcloud-file4
- it will move identicalcloud-file1 file to identicalcloud-file4 file
$mv IdenticalCloud-dir1/ IdenticalCloud-dir4/
- it will move all files and folders of IdenticalCloud-dir1 directory recusrively to IdenticalCloud-dir4 directory
If it's same directory, you can consider, it will perform rename operation
13. cat
cat
command is used to read,write and edit file
$cat identicalcloud-file1
- it will print content of file identicalcloud-file1
$cat > identicalcloud-file1
- it will erase current data in identicalcloud-file1 file and allows you to write new data
- after you are done writing new data, you can save file with ctrl+D
$cat >> identicalcloud-file1
- it will keep current data as it is, and will append your new data at last
- after you are done appending new data, you can save file with ctrl+D
14. whoami
whoami
command is used to check username that you are currently logged in with
$whoami
ubuntu
15. passwd
Last but not the least, to change your password using the command line, use passwd
command
$passwd
It will prompt to enter current password
after successfully entering current password, it will prompt to add new password
While doing this operation in ubuntu/such linux systems, they don't show you how many characters you have typed
Stay tuned for more such important Linux command’s history. Like, Comment and share!
Drafted On,
22nd January 2022
DevOps @identicalCloud.com