0% found this document useful (0 votes)
2 views10 pages

Commandos-Linux Follow Codes

The document provides a comprehensive overview of various Linux commands categorized into sections such as File and Directory Management, User and Group Management, Disk Management, and more. Each section lists essential commands along with brief descriptions of their functionalities. This serves as a quick reference guide for users to manage files, processes, networks, and system services in a Linux environment.

Uploaded by

raimol gensan
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)
2 views10 pages

Commandos-Linux Follow Codes

The document provides a comprehensive overview of various Linux commands categorized into sections such as File and Directory Management, User and Group Management, Disk Management, and more. Each section lists essential commands along with brief descriptions of their functionalities. This serves as a quick reference guide for users to manage files, processes, networks, and system services in a Linux environment.

Uploaded by

raimol gensan
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/ 10

1.

File and Directory Management

 ls : Lists the contents of a directory


 cp : Copies files and directories
 mv : Moves or renames files and directories
 rm : Removes (deletes) files or directories
 touch : Creates a new empty file or update file mestamps
 nano : Text editor (terminal-based)
 vim / vi : Advanced text editors
 cat : Concatenates and displays file content
 tac : Concatenate and display file content in reverse
 less : Displays file content one screen at a me, allowing for scrolling
 more : Displays file content one screen at a me, but with less func onality than less
 head : Displays the beginning of a file
 tail : Displays the end of a file
 diff : Compares two files line by line
 grep : Searches for pa erns within files
 find : Searches for files and directories in a directory hierarchy
 file : Determines file type
 chmod : Changes file permissions
 chown : Changes file owner
 chgrp : Changes file group ownership
 ln : Creates links (hard or symbolic) between files
 locate : Find files by name
 stat : Display file or file system status
 sed : Stream editor for filtering and transforming text.
 awk : Pa ern scanning and processing language
 cut : Remove sec ons from each line of files
 sort : Sort lines of text files.
 uniq : Report or omit repeated lines

Directory Commands
 pwd : Prints the current working directory
 cd : Changes the current directory
 mkdir : Creates new directories
 rmdir : Removes empty directories
 tree : Lists contents of directories in a tree-like format
2.Filesystem Permissions and Security
 chmod : Change file permissions
o chmod 755 file.txt – Give read, write, and execute permissions to owner, and
read-execute permissions to others

 chown : Change file owner and group


o chown user:group file.txt – Change owner and group of a file
 chgrp : Change group ownership of a file
o chgrp group file.txt – Change the group of a file
 umask : Set default permissions for new files
o umask 022 – Set default permissions for newly created files to 755
 se acl : Set access control lists (ACL) for file permissions
 ge acl : Get access control lists (ACL) for file permissions

3.User and Group Management


 useradd : Creates a new user account
 adduser : Creates a new user account with interac ve prompts and generally sets up
a home directory and other default configura ons
 userdel : Deletes a user account
 usermod : Modifies an exis ng user account’s proper es
 passwd : Changes a user's password
 chage : Changes user password expiry informa on
 id : Displays user and group iden ty informa on
 whoami : Displays the effec ve username of the current user
 su : Switches to another user account or becomes the superuser
 sudo : Executes a command with elevated privileges
 last : Displays informa on about the last logged-in users
 who : Displays informa on about currently logged-in users
 groupadd : Creates a new group
 groupdel : Deletes a group
 groupmod : Modifies an exis ng group's proper es
 groups : Displays the groups a user belongs to
 newgrp : Changes the current group ID, effec vely switching to a new group for the
current session
 gpasswd : Administers the /etc/group and /etc/gshadow files, used for managing
group passwords and memberships
 chgrp : Changes the group ownership of files or directories

4.Disk Management
 lsblk : Lists block devices, including disks and their par ons, in a tree-like format
 fdisk : par on table manipulator for linux
 parted : A par on manipulator program
 blkid : Locates and displays the a ributes (UUID, LABEL, TYPE) of block devices
 df : Reports filesystem disk space usage
 du : Es mates file and directory space usage

Filesystem Crea on
 mkfs : Builds a Linux filesystem on a device or par on. It's a front-end for various
filesystem-specific tools (e.g., mkfs.ext4, mkfs.xfs)
 mkswap : Sets up a Linux swap area
 fsck : Checks and op onally repairs a Linux filesystem. It's a front-end for filesystem-
specific check tools (e.g., fsck.ext4)
 e2fsck : Checks and repairs ext2, ext3, or ext4 filesystems

Moun ng and Unmoun ng Filesystems


 mount : A aches a filesystem to a specified mount point in the directory tree, making
it accessible
 umount : Detaches a mounted filesystem from the directory tree
 /etc/fstab : A system configura on file that contains informa on about filesystems to
be mounted automa cally at boot me

Logical Volume Management (LVM)


 pvcreate : Ini alizes a physical volume for use by LVM
 pvdisplay : Displays a ributes of physical volumes
 vgcreate : Creates a volume group
 vgdisplay : Displays a ributes of volume groups
 lvcreate : Creates a logical volume
 lvdisplay : Displays a ributes of logical volumes
 lvextend : Extends the size of a logical volume
 lvreduce : Reduces the size of a logical volume
 vgremove : Removes a volume group
 lvremove : Removes a logical volume
5.Process management
 ps : Report a snapshot of current processes.
 top : Display Linux tasks.
 htop : Interac ve process viewer (advanced top).
 kill : Send a signal to a process, typically to terminate.
 killall : Terminate processes by name.
 bg : Resume a suspended job in the background.
 fg : Bring a job to the foreground.
 jobs : List ac ve jobs.
 nice : Run a program with modified scheduling priority.
 renice : Alter priority of running processes.
 up me : Show how long the system has been running.
 me : Measure program running me.

6. Network management
 ifconfig : displays and configure network interfaces
 ip a : shows all network interfaces and their Ips
 ip r : displays the rou ng tables
 ping : Send ICMP Echo requests to network hosts
 netstat : show open ports and listening services
 ss : Socket sta s cs and listening services (faster than netstat)
 traceroute : Trace the route packets take to a network host
 nslookup : Query Internet name servers interac vely
 dig : DNS lookup u lity
 wget : Non-interac ve network downloader
 curl : Transfer data with URLs
 scp : Secure copy files between hosts
 ssh : Secure shell for remote login
 p : File Transfer Protocol client

7. system informa on and monitoring


 uname : print system informa on
 hostname : Shows or sets the system's hostname
 lsusb : Lists USB devices connected to the system
 lspci : Lists PCI devices connected to the system
 lshw : Lists hardware configura on
 top : Displays dynamic processes and system informa on
 htop : Interac ve process and resource monitoring
 ps : Report a snapshot of current process
 free : Displays the total, used, and free amounts of physical and swap memory
 df : Reports file system disk space usage
 du : Es mates file space usage for files or directories.
 Iostat : Reports CPU u liza on and I/O sta s cs for devices and par ons.
 vmstat : Report virtual memory sta s cs
 netstat : show open ports and listening services
 up me : Shows system up me and load averages (1, 5, and 15 minutes).
 who : Displays informa on about users currently logged in.
 w : Shows who is logged on and what they are doing
 dmesg : Print the kernel ring buffer messages (system boot and hardware related
message)
 journalctl : Query and view logs from system’s journal

8. package management (depends on distribu ons)


Debian-based (e.g., Ubuntu)

 apt-get : APT package handling u lity


o apt-get install : Install a package
o apt-get update : Update package list
o apt-get upgrade : Upgrade installed packages
o apt-get remove : Remove a package
 apt-cache : Query APT cache
o apt-cache search : Search for a package
o apt-cache show : Show package details
Red Hat-based (e.g., CentOS, Fedora)

 yum : Package manager for RPM-based systems


o yum install : Install a package
o yum update : Update installed packages
o yum remove : Remove a package
 dnf : Next-genera on package manager (Fedora, CentOS 8+)
o dnf install : Install a package
o dnf update : Update installed packages
o dnf remove : Remove a package
General Commands

 rpm : RPM package manager


o rpm -i : Install an RPM package
o rpm -e : Remove an RPM package
 dpkg – Debian package manager
o dpkg -i : Install a Debian package
o dpkg -r : Remove a Debian package

9. System Services and Daemon Management


 systemctl : Control the systemd system and service manager
o systemctl start : Start a service
o systemctl stop : Stop a service
o systemctl restart : Restart a service
o systemctl enable : Enable a service to start on boot
o systemctl disable : Disable a service from star ng on boot
o systemctl status : Check service status
 service : Older service management command (used in non systemd systems)
o service start : Start a service
o service stop : Stop a service
o service restart : Restart a service
o service status : Check service status

10. Archiving and Compression


Working with tar files

 tar -cvf archive.tar < files > : create a ter archive


 tar -xvf archive.tar : extract a tar archive
 tar -tvf archive.tar : list files in a tar archive
 tar -czvf archive.tar.gz < files > : create a compressed tar.gz archive
 tar -xzvf archive.tar.gz : extract a tar.gz archive
 tar -cJvf archive.tar.xz : Create a tar.xz archive
 tar -xJvf archive.tar.xz : Extract a tar.xz archive
Working with zip files

 zip archive.zip <files> : Create a zip archive


 unzip archive.zip : Extract a zip archive
 unzip -l archive.zip : List contents of a zip file
 zip -r archive.zip : Zip a directory
Working with gzip & bzip2

 gzip <file> : Compress a file using gzip


 gunzip <file> .gz : Decompress a gzip file
 bzip2 <file> : Compress a file using bzip2
 bunzip2 <file>.bz2 : Decompress a bzip2 file

11.Text Processing
 grep : Search for pa erns within files
o grep 'pa ern' file.txt – Search for a pa ern in a file
o grep -r 'pa ern' /dir/ – Recursively search for a pa ern
 sed : Stream editor for filtering and transforming text
o sed 's/old/new/g' file.txt – Replace old with new globally
 awk : A powerful text processing language
o awk '{print $1}' file.txt – Print the first column of each line in a file
 cut : Remove sec ons from each line of a file
o cut -d ':' -f 1 /etc/passwd – Print the first field of each line, delimited by ":"
 sort : Sort lines of text files
o sort file.txt – Sort file content in ascending order
 uniq : Report or omit repeated lines in a file
o sort file.txt | uniq – Sort and remove duplicate lines
 tee : Read from standard input and write to standard output and files
o echo "text" | tee file.txt – Write to file and show output on screen
 tr : Translate or delete characters
o echo "hello" | tr 'a-z' 'A-Z' – Convert lowercase to uppercase
 paste : Merge lines of files
o paste file1.txt file2.txt – Combine lines of file1 and file2 side by side
 wc : Word, line, character, and byte count
o wc -l file.txt – Count lines in a file
o wc -w file.txt – Count words in a file
12. System Shutdown and Reboot
 shutdown : Shut down the system
o shutdown -h now : Immediately shut down
o shutdown -r now : Reboot the system
o shutdown -h +10 : Shut down a er 10 minutes
o shutdown -h 22:00 : Schedule shutdown at 10:00 PM
o shutdown -c : Cancel a scheduled shutdown
 reboot : Reboot the system
 halt : Halt the system immediately (equivalent to turning off power)
 poweroff : Power off the system
 init : Change the runlevel (old-style system manager)
o init 0 : Shutdown
o init 6 : Reboot

13. System Diagnos cs and Troubleshoo ng


 dmesg : Print the kernel ring buffer messages (system boot and hardware-related
messages)
 journalctl : Query and view logs from systemd’s journal
 strace : Trace system calls and signals
o strace : Trace a command’s system calls
 lsof : List open files (useful for debugging)
o lsof : Show processes using a specific file
 vmstat : Report virtual memory sta s cs
 iostat : Report CPU and I/O sta s cs
 mpstat : Report CPU usage sta s cs
 pidstat : Report sta s cs by process
 free : Display memory usage
 up me : How long the system has been running
 watch : Execute a program periodically, showing output
o watch -n 1 free – Watch memory usage every second
 lshw : List hardware configura on
 htop : Interac ve process viewer (be er than top)
 netstat : Network sta s cs (deprecated in favor of ss)
 ss : Show socket sta s cs (more efficient than netstat)
14. Networking & Remote Management
 ifconfig : Configure network interfaces (older command, replaced by ip)
 ip : A more modern alterna ve for managing network interfaces and rou ng
o ip addr : Show IP addresses
o ip link : Show or manipulate network interfaces
o ip route : Show or manipulate rou ng tables
 ss : Display socket sta s cs (useful for diagnosing network issues)
 nmap : Network explora on tool (can be used for security audi ng)
 telnet : User interface to the TELNET protocol (less common nowadays)
 nc (Netcat) : Network u lity for reading and wri ng from network connec ons
o nc -l -p 1234 : Listen on port 1234
o nc <host><port> : Connect to a host and port
 iptables : Administra on tool for IPv4 packet filtering and NAT (Network Address
Transla on)
 firewalld : Frontend for managing firewall rules (used in some distros like Fedora and
CentOS)
 ufw : Uncomplicated firewall (front-end for iptables)
o ufw enable – Enable firewall
o ufw allow <port> – Allow traffic on a specific port
 tcpdump : Command-line packet analyzer
 curl : Transfer data from or to a server using various protocols (HTTP, FTP, etc.)
 wget : Download files from the web via HTTP, HTTPS, FTP
 scp : Secure copy over SSH (used to copy files between systems)
o scp file.txt user@remote:/path/to/des na on/ – Copy file to remote server
 rsync : Remote file and directory synchroniza on (o en used for backups)
o rsync -avz /local/path/ remote:/remote/path/ – Sync directories

15. Task Scheduling


 cron : Daemon for running scheduled commands
o crontab -e : Edit cron jobs for the current user
o crontab -l : List the current user’s cron jobs
o crontab -r : Remove the current user's cron jobs
 at : Run commands at a specified me
o at 09:00 : Schedule a command to run at 09:00 AM
 batch : Run commands when the system load is low
 sleep : Delay for a specified me
o sleep 5s – Sleep for 5 seconds

16. System Backup and Restore


 rsync : Remote file and directory synchroniza on
o rsync -avz source/ des na on/ : Synchronize files
o rsync -avz -e ssh source/ user@remote:/des na on/ : Sync over SSH
 cpio : Copy files to and from archives
 dd : Low-level copying and backup of en re filesystems
o dd if=/dev/sda of=/path/to/backup.img : Backup a disk/par on
o dd if=/path/to/backup.img of=/dev/sda : Restore a disk/par on

You might also like