Gmail - Linux Command
Gmail - Linux Command
Linux Command
Amritanshu Vishwakarma <amritaanshu1455@gmail.com> 1 December 2024 at 11:49
Draft To: "badalsah8541@gmail.com" <badalsah8541@gmail.com>
➜ ~ hostname
localhost
➜ ~ hostid
0a123456
➜ ~ date
Wed Jan 19 12:34:56 UTC 2024
uptime - shows the elapsed time duration since the machine logged in.
➜ ~ uptime
12:34:56 up 1 day, 3:45, 2 users, load average: 0.25, 0.20, 0.18
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 1/18
01/12/2024, 11:49 Gmail - Linux Command
➜ ~ uname
Linux
➜ ~ clear
➜ ~ history
1 ls
2 cd Documents
3 nano file.txt
4 gcc program.c -o program
5 ./program
6 history
➜ ~ sudo su - USERNAME
echo $? - shows the exit status of the last executed command (0 - success, 1-
255 - error/failure).
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 2/18
01/12/2024, 11:49 Gmail - Linux Command
➜ ~ echo $?
127
➜ ~ printenv
TERM=xterm-256color
SHELL=/bin/bash
USER=your_username
...
➜ ~ last
root pts/0 Wed Jan 19 12:34 still logged in
reboot system boot 5.4.0-96-generic Wed Jan 19 12:33 still running
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 3/18
01/12/2024, 11:49 Gmail - Linux Command
preset: enabled)
Active: active (running) since Wed 2024-01-19 12:34:56 UTC; 1 day 3h
ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1234 ExecStartPre=/usr/sbin/sshd -t (code=exited,
status=0/SUCCESS)
Main PID: 5678 (sshd)
Tasks: 1 (limit: 1234)
Memory: 2.3M
CPU: 12ms
CGroup: /system.slice/sshd.service
└─5678 /usr/sbin/sshd -D
File Commands
cat > <fileName> - creates a new file, allows to input content interactively
and redirects inputted content to the created file (> redirection operator).
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 4/18
01/12/2024, 11:49 Gmail - Linux Command
➜ ~ head -n 5 help.txt
1. Commands shortcut
....
5. huddle - Connect to Syncup Call
➜ ~ tail -F mySystem.logs
echo "I love DevOps"
echo "Best Linux commands"
....
less <fileName> - used to view large files (log files) in a paginated manner.
rm - remove command.
rm -rf <dirName> - force remove the files & folders of directory recursively
(-f force).
Example: rm -r ./test
cp - copy command.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 5/18
01/12/2024, 11:49 Gmail - Linux Command
➜ ~ ls -l .
total 1016
-rw-r--r-- 1 vinodhakumaral staff 48 Jan 19 21:06 crazy.sh
-rw-r--r-- 1 vinodhakumaral staff 2463 Jan 2 11:25 help
-rw-r--r-- 1 vinodhakumaral staff 48 Jan 19 22:14 mySystem.logs
drwxr-xr-x@ 8 vinodhakumaral staff 256 Dec 20 12:51 observability-
signoz
➜ ~ ls -ld Downloads
drwx------@ 53 vinodhakumaral staff 1696 Jan 19 21:00 Downloads
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 6/18
01/12/2024, 11:49 Gmail - Linux Command
➜ ~ getfacl filename.txt
# file: filename.txt
# owner: user1
# group: group1
user::rw-
group::r--
other::r--
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 7/18
01/12/2024, 11:49 Gmail - Linux Command
useradd <userName> - Creates user account without home & mail spool
directories.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 8/18
01/12/2024, 11:49 Gmail - Linux Command
useradd -m <userName> - Creates user account with home & mail spool
directories.
passwd <userName> - The system generates a password for the user and then
stores it in the /etc/shadow file.
userdel -r <userName> - deletes the user from the system along with home
and mail spool directories.
su - substitute user.
Example: su - ram
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-814230… 9/18
01/12/2024, 11:49 Gmail - Linux Command
usermod -aG <groupName> <userName> - adds the user to another group (-aG
append the user to the group without removing from other groups).
chsh -s /bin/bash <user> - changes the shell to bash for the user.
Searching Commands
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 10/18
01/12/2024, 11:49 Gmail - Linux Command
find <dirName> -perm 754 - finds the files in the directory having 754
permission.
locate is faster for finding files by name due to its pre-built database,
while find is more versatile, allowing complex searches based on various
criteria in real-time.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 11/18
01/12/2024, 11:49 Gmail - Linux Command
ack-grep (Ack)
du - Disk usage.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 12/18
01/12/2024, 11:49 Gmail - Linux Command
scp - Securely Copy Files: Copy files between local and remote systems using
SSH.
Example: scp file.txt user@remote_host:/path
Network Commands
ping <hostName> - tests the reachability & responsiveness of the remote host.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 13/18
01/12/2024, 11:49 Gmail - Linux Command
netstat -antp - shows all tcp open ports (-a all, t-tcp, n-active, p protocol).
traceroute <url> - traces the route using packets from source to destination
host.
ps - Process status.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 14/18
01/12/2024, 11:49 Gmail - Linux Command
tar -cvf <fileName> <directory> - creates the tar file with the fileName
for the directory mentioned (-c create, -v verbose, -f output file name).
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 15/18
01/12/2024, 11:49 Gmail - Linux Command
apt purge <packageName> - removes the required package along with its config
files.
Note: For other package manager just replace “apt” with other package
manager
Directory Commands
pwd - shows the present working directory (abbr. Print Working Directory).
cd - change directory.
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 16/18
01/12/2024, 11:49 Gmail - Linux Command
ls - lists the files & folders of the directory you are in.
ls -a - lists all files & folders along with hidden files (-a all).
ls -al - lists all files & folders along with hidden files in a formatted
manner (-l long listing format).
Misc Commands
man - Displays the manual page for a specific command. Provides detailed
information and usage instructions.
wc -(Word Count)
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 17/18
01/12/2024, 11:49 Gmail - Linux Command
ln -(Create Links):
echo "sample text" | grep text - The output of the first command is
passed as an input to the second command using the pipe (|) symbol.
echo "sample text" > <fileName> - Write the content to the file mentioned
by overwriting the existing content (> redirection operator).
echo "new sample text" >> <fileName> - Appends the contents to the file
mentioned without overwriting the existing content (>> redirection
operation).
Conclusion
https://mail.google.com/mail/u/0/?ik=af8bed5240&view=pt&search=drafts&permmsgid=msg-a:r-8142300951627776943&dsqt=1&simpl=%23msg-a:r-81423… 18/18