Most Usefull Commands in Linux
Most Usefull Commands in Linux
. – This directory
cp -r Copy directories cp -r dir1 dir2 Copies directory dir1 and its contents to dir2
recursively
mv Move or rename files or mv file1 file2 Moves or renames file1 to file2
directories
mv -i Prompt before mv -i file1 file2 Prompts before overwriting file2 with file1
overwrite
rename Rename multiple files rename Renames all files by replacing 'old' with 'new'
's/old/new/' *
Section 9: Wildcards
Wildcard Description Example Explanation
* Matches any number of characters ls *.txt Lists all .txt files in the directory
? Matches a single character ls file?.txt Lists files like file1.txt, file2.txt
[] Matches any one of the enclosed ls file[13].txt Lists files file1.txt, file2.txt,
characters file3.txt
{} Matches any of the patterns within ls file{1,2}.txt Lists files file1.txt, file2.txt
braces
Section 10: Input and Output Redirection
Command Description Example Explanation
> Redirect output to a file, echo "Hello" > file.txt Writes "Hello" to file.txt, creating or
overwriting it overwriting it
>> Append output to a file echo "Hello" >> file.txt Appends "Hello" to the end of file.txt
< Redirect input from a file wc -l < file.txt Counts the lines in file.txt
` ` Pipe output to another `ls
command
Section 11: Searching Files and Directories
Command Description Example Explanation
find Search for files and find /home -name "*.txt" Finds all .txt files in /home and its
directories subdirectories
locate Quickly find files by locate file.txt Searches the prebuilt database for
name file.txt
grep Search text using patterns grep "hello" file.txt Searches for the string "hello" in file.txt
grep -r Recursively search grep -r "hello" /home Recursively searches for "hello" in
directories /home
/bin Essential user binaries and commands. Common commands like ls, cp, mv, cat.
/boot Static files for bootloader. Kernel images, bootloader configuration files
(e.g., vmlinuz, initrd.img).
/dev Device files; represents hardware devices. Device files like /dev/sda, /dev/tty0, /dev/null.
/etc System-wide configuration files. Configuration files for system services and
applications (e.g., passwd, fstab, network).
/mnt Mount point for temporarily mounted Temporary mounts (e.g., external drives).
filesystems.
/opt Optional application software packages. Add-on application software (e.g.,
/opt/application).
/proc Virtual filesystem providing process and Kernel and process information (e.g.,
system information. /proc/cpuinfo,
/proc/meminfo).
/root Home directory for the root user. Root user's personal files and settings.
/run Runtime data; information about the PID files, lock files.
system since the last boot.
/srv Data for services provided by the system. Data for services (e.g., /srv/www for web data).
/sys Virtual filesystem for kernel and device Kernel and device information (e.g., /sys/class).
information.
/tmp Temporary files created by applications. Temporary files and directories.
/usr/sbin System binaries for administrative tasks. System management commands (e.g., useradd,
shutdown).
/usr/local Local software and scripts installed by the Locally installed software and scripts.
user.
/var Variable data; files that change frequently. Logs, spool files, mail, and temporary files
(/var/log,
/var/spool).
/var/log System and application log files. Log files for system and applications.
/var/spool Spool directories for tasks and services. Mail queues, print jobs.
/var/tmp Temporary files that need to persist Persistent temporary files.
between reboots.
/var/lib Variable data used by applications and Database files, application state information.
services.
/var/cache Cached data from applications. Cached files to speed up application performance.
/var/run Runtime information such as system and PID files, process runtime data.
service status.
/var/opt Variable data for applications installed in Application-specific data (similar to /opt).
/opt.
/etc/passwd User account information. Contains user User account entries (e.g.,
details like username, UID, GID, and home root:x:0:0:root:/root:/bin/bash).
directory.
/etc/shadow Contains hashed passwords and account Password hashes and expiration info.
expiration information.
/etc/group Defines user groups and their members. Group definitions (e.g., root:x:0:).
/etc/fstab Static filesystem information; lists Filesystem mount details (e.g., /dev/sda1 / ext4
filesystems and mount points. defaults 0 1).
/etc/hosts Static table of IP addresses to hostnames. IP address and hostname mappings.
/etc/hostname Contains the system’s hostname. The system’s hostname.
/etc/resolv.conf DNS resolver configuration file. Nameserver IPs and domain search paths.
/etc/sysctl.conf Configuration file for kernel parameters. Kernel parameter settings (e.g.,
net.ipv4.ip_forward=1).
/etc/network/interfaces Network interface configuration file (used Network interface settings (e.g., auto eth0 iface
in Debian-based systems). eth0 inet dhcp).
/var/log/httpd/ Directory for Apache HTTP server logs Apache access and error logs.
(may vary by distribution).
/var/log/nginx/ Directory for Nginx web server logs (may Nginx access and error logs.
vary by distribution).