Linux For Devops
Linux For Devops
2. uptime:
● This command displays how long the system has been running and the current system
load average.
● It typically shows the current time, the length of time the system has been up, the
number of users logged in, and the system load averages for the past 1, 5, and 15
minutes.
● Example: uptime displays system uptime and load averages.
3. date:
● This command displays or sets the system date and time.
● It can be used to print the current date and time or to set the system clock to a specific
date and time.
● Example: date displays the current date and time.
4. who:
● This command displays information about currently logged-in users.
● It shows the username, terminal, login time, and source IP address (if available) of each
logged-in user.
● Example: who displays a list of logged-in users.
5. whoami:
● This command prints the username of the current user.
● It simply returns the username associated with the current user's session.
● Example: whoami displays the current username.
6. which:
● This command displays the full path to the executable file of a given command.
● It helps to identify the location of a command's executable file in the system's PATH
environment variable.
● Example: which ls displays the path to the ls command.
7. id:
● This command displays the user and group IDs of the current user or a specified user.
● It provides information about the user's UID (user ID), GID (group ID), and supplementary
group memberships.
● Example: id displays the user and group IDs of the current user.
8. sudo:
● This command allows users to execute commands with the privileges of another user,
typically the root user.
● It is commonly used to perform administrative tasks that require elevated permissions.
● Example: sudo apt update updates the package repository using elevated privileges.
9. shutdown and reboot:
● These commands are used to shut down or reboot the system.
● The shutdown command can be used to schedule a system shutdown or reboot at a
specified time, and it also allows sending a message to users.
● Example: shutdown -r now reboots the system immediately.
● Example: shutdown +10 "System will be rebooting in 10 minutes"
schedules a system reboot in 10 minutes.
various tasks ranging from system administration to software installation and maintenance.
2. whoami:
● This command prints the username of the current user.
● It simply returns the username associated with the current user's session.
● Example: whoami displays the current username.
3. passwd:
● This command is used to change a user's password.
● If run without any arguments, it prompts the current user to change their
password.
● Syntax: passwd [username]
● Example: passwd john allows the user "john" to change their password.
4. su:
● This command allows switching to another user account.
● By default, it switches to the root user account, but you can specify another user's
username as an argument.
● Syntax: su [username]
● Example: su pardeep switches to the user account "pardeep".
5. userdel:
● This command is used to delete a user account from the system.
● By default, it only removes the user's entry from the /etc/passwd file and does
not delete their home directory or any files owned by the user.
● Syntax: userdel [options] username
● Common options:
● -r: Remove the user's home directory and mail spool.
● Example: userdel -r pardeep deletes the user account "pardeep" and removes
their home directory.
6. groupadd:
● This command is used to create a new group on the system.
● Syntax: groupadd [options] groupname
● Example: groupadd developers creates a new group named "developers".
Cat /etc/group
7. gpasswd:
● This command is used to administer the /etc/group file and manage group
membership.
● Syntax:
● To add a user to a group: gpasswd -a username groupname
● To set the group's password: gpasswd groupname
● To make a user the group's owner: gpasswd -m username groupname
● Example: gpasswd -a pardeep developers adds the user "pardeep" to the
group "developers".
These commands are essential for managing user accounts, groups, and permissions on a Linux
system, allowing administrators to control access to resources and perform user-related tasks
efficiently.
3. chmod:
● The chmod command is used to change the permissions of files and directories.
● It allows you to add, remove, or set specific permissions for the owner, group, and
others.
● Permissions can be specified using symbolic notation (e.g., u+r, g-w, o+x) or octal
notation (e.g., 755, 644).
● Syntax: chmod [options] mode file
● Example: chmod u+x script.sh adds execute permission for the owner to the file
script.sh.
4. chown:
● The chown command is used to change the ownership of files and directories.
● It allows you to change both the user owner and the group owner of a file or
directory.
● Syntax: chown [options] owner[:group] file
● Example: chown user:group file.txt changes the owner of the file file.txt to
user and the group owner to group.
5. chgrp:
● The chgrp command is used to change the group ownership of files and
directories.
● It allows you to change the group owner of a file or directory without changing the
user owner.
● Syntax: chgrp [options] group file
● Example: chgrp group file.txt changes the group owner of the file file.txt
to group.
These file permission commands are essential for managing access control and security settings
on Linux systems, allowing administrators to control who can read, write, and execute files and
directories.
Compression commands:
1. zip:
● The zip command is used to compress files and directories into a ZIP archive
format.
● It can also be used to extract files from ZIP archives.
● Syntax for compression: zip [options] zipfile files/directories
● Syntax for extraction: unzip zipfile
● Example for compression: zip -r archive.zip directory/ compresses the
contents of the "directory" into a ZIP archive named "archive.zip".
● Example for extraction: unzip archive.zip extracts the contents of the ZIP
archive "archive.zip" into the current directory.
2. Unzip, gunzip:
● The unzip command is used to decompress files that have been compressed
using the gzip algorithm.
● It can decompress files with extensions like .gz, .z, .Z.
● Syntax: unzip [options] filename
● Example: unzip file.txt.zip decompresses the file "file.txt.zip" and creates a
new uncompressed file "file.txt".
3. gzip:
● The gzip command is used to compress files using the gzip algorithm.
● It replaces the original file with a compressed version having the extension .gz.
● Syntax: gzip [options] filename
● Example: gzip file.txt compresses the file "file.txt" and creates a new
compressed file "file.txt.gz".
4. tar:
● The tar command is used to create, list, and extract files from tar archives.
● It can be used with various compression algorithms (e.g., gzip, bzip2) to create
compressed tar archives.
● Syntax for compression: tar -czvf archive.tar.gz files/directories
● Syntax for extraction: tar -xzvf archive.tar.gz
● Example for compression: tar -czvf archive.tar.gz directory/ creates a
compressed tar archive named "archive.tar.gz" containing the contents of the
"directory".
● Example for extraction: tar -xzvf archive.tar.gz extracts the contents of the
compressed tar archive "archive.tar.gz" into the current directory.
5. untar:
● There's no specific "untar" command. To extract files from a tar archive, you use
the tar command with appropriate options, as shown above.
2. rsync:
● rsync is a powerful command-line utility used for file synchronization and transfer.
● It is particularly useful for synchronizing files between local and remote systems or
between directories on the same system.
● Syntax: rsync [options] source destination
● Example: rsync -avz /local/directory/
user@example.com:/remote/directory/ synchronizes the contents of the local
directory "/local/directory/" with the directory "/remote/directory/" on the remote host
"example.com".
These file transfer commands and protocols offer different features and capabilities, allowing users to
transfer files securely and efficiently between systems in a Unix-like environment. The choice of
command or protocol depends on factors such as security requirements, network configuration, and
user preferences.