0% found this document useful (0 votes)
157 views16 pages

Linux For Devops

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views16 pages

Linux For Devops

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Linux for devops.

User and file management


1. uname:
● This command displays system information about the current operating system.
● Commonly used options include:
● -a: Print all system information.
● -s: Print the kernel name.
● -r: Print the kernel release.
● -m: Print the machine hardware name.
● Example: uname -a displays all system information.

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.

10. apt, yum, dnf, pacman, portage:


● These are package management commands used in various Linux distributions to
install, update, and manage software packages.
● They are specific to different package management systems used by different
distributions:
● apt: Used by Debian-based distributions like Ubuntu.
● yum and dnf: Used by RPM-based distributions like Fedora and CentOS/RHEL
(dnf is the newer version).
● pacman: Used by Arch Linux and its derivatives.
● portage: Used by Gentoo Linux.
● Example: apt install <package> installs a package using the APT package
manager.
Sudo apt-get update
Sudo apt-get install docker.io -y

11. Cat /etc/passwd:


● It will show list of users
These commands are fundamental tools for managing and interacting with Linux systems, performing

various tasks ranging from system administration to software installation and maintenance.

User and group management commands


1. useradd:
● This command is used to create a new user account on the system.
● Syntax: useradd [options] username
● Common options:
● -m: Create the user's home directory if it doesn't exist.
● -s <shell>: Set the user's login shell.
● Example: useradd -m john creates a new user account named "john" with a
home directory.

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".

To add multiple users


8. groupdel:
● This command is used to delete a group from the system.
● Syntax: groupdel groupname
● Example: groupdel developers deletes the group "developers" from the system.

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.

File permission commands:


1. umask:
● The umask command sets the default file permissions for newly created files and
directories.
● It works by subtracting the specified file mode from the default permission settings
(usually 666 for files and 777 for directories).
● The result is the actual permission that is applied when a new file or directory is
created.
● Syntax: umask [mode]
● Example: umask 022 sets the default permission for newly created files to 644 and
for directories to 755.
2. ls -l:
● The ls -l command is used to list files and directories in long format, showing
detailed information about permissions, ownership, size, modification date, and
filename.
● It displays file permissions in the format -rwxr-xr-x, where the first character
indicates file type, and the next nine characters represent permission settings for
the owner, group, and others.
● Syntax: ls -l [path]
● Example: ls -l /home/user lists files and directories in long format in the
/home/user directory.

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.

File transfer commands:


There are several commands and protocols commonly used for transferring files between systems in a
Unix-like environment. Here are some of the most common ones:

1. scp (Secure Copy):


● scp is a command-line tool used to securely transfer files between a local and a remote
host or between two remote hosts over SSH (Secure Shell).
● Syntax for copying from local to remote: scp [options] local_file
remote_user@remote_host:remote_path
● Syntax for copying from remote to local: scp [options]
remote_user@remote_host:remote_path local_path
● Example: scp file.txt user@example.com:/remote/directory/ copies the file
"file.txt" from the local system to the remote host "example.com" into the directory
"/remote/directory/".

1. Copy from local to server


scp -i "/Users/kamal/OneDrive/Desktop/votingproject.pem" ffilee2.txt
ubuntu@ec2-99-79-194-251.ca-central-1.compute.amazonaws.com:/home/ubuntu

Create file on local


Now copy this file from local to server:

2. Copy from server to local


scp -i "/Users/kamal/OneDrive/Desktop/votingproject.pem" -r
ubuntu@ec2-99-79-194-251.ca-central-1.compute.amazonaws.com
:/home/ubuntu/cloud1 .

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".

3. sftp (SSH File Transfer Protocol):


● sftp is a command-line tool and interactive file transfer protocol similar to FTP, but it
operates over an encrypted SSH connection.
● It provides a secure way to transfer files between hosts and perform file operations
such as listing directories, uploading, and downloading files.
● Syntax: sftp [options] user@hostname
● Example: sftp user@example.com starts an interactive SFTP session with the remote
host "example.com".
4. wget and curl:
● wget and curl are command-line tools used for downloading files from remote
servers.
● They support various protocols, including HTTP, HTTPS, FTP, and FTPS.
● Syntax for wget: wget [options] URL
● Syntax for curl: curl [options] URL
● Example with wget: wget http://example.com/file.txt downloads the file
"file.txt" from the URL "http://example.com/".
● Example with curl: curl -O http://example.com/file.txt downloads the file
"file.txt" from the URL "http://example.com/".
5. FTP (File Transfer Protocol):
● FTP is a standard network protocol used for transferring files between a client and a
server on a computer network.
● It operates over TCP/IP and supports both ASCII and binary file transfer modes.
● Various FTP clients such as ftp, lftp, and graphical clients like FileZilla are available
for transferring files using FTP.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy