April 22, 2025

Basic Commands

1. ls

Usage: Lists directory contents.

Example: ls (lists files in the current directory).

2. cd

Usage: Changes the current directory.

Example: cd /home/user (changes to the /home/user directory).

3. pwd

Usage: Prints the current working directory.

Example: pwd (displays the current directory path).

4. mkdir

Usage: Creates a new directory.

Example: mkdir new_directory (creates a directory named new_directory).

5. rmdir

Usage: Removes an empty directory.

Example: rmdir old_directory (removes the directory old_directory).

6. mv

Usage: Moves or renames files or directories.

Example: mv oldname newname (renames oldname to newname).

7. cp

Usage: Copies files or directories.

Example: cp source destination (copies source to destination).

8. open

Usage: Opens files or directories (mostly used in macOS).

Example: open filename (opens the file named filename).

9. touch

Usage: Creates an empty file or updates the timestamp of an existing file.

Example: touch newfile (creates a new empty file named newfile).

10. find

Usage: Searches for files and directories.

Example: find /path -name filename (finds filename in the specified path).

11. ln

Usage: Creates hard and symbolic links.

Example: ln -s target linkname (creates a symbolic link linkname to target).

Compression and Archiving

  1. gzip
    • Usage: Compresses files.
    • Example: gzip filename (compresses filename).
  2. gunzip
    • Usage: Decompresses files.
    • Example: gunzip filename.gz (decompresses filename.gz).
  3. tar
    • Usage: Archives files.
    • Example: tar -cvf archive.tar directory (creates an archive archive.tar of the directory).

Customization and Viewing Files

  1. alias
    • Usage: Creates shortcuts for commands.
    • Example: alias ll='ls -la' (creates an alias ll for ls -la).
  2. cat
    • Usage: Concatenates and displays file contents.
    • Example: cat filename (displays the contents of filename).
  3. less
    • Usage: Views file contents one screen at a time.
    • Example: less filename (opens filename for viewing).
  4. tail
    • Usage: Displays the last part of a file.
    • Example: tail filename (displays the last 10 lines of filename).
  5. wc
    • Usage: Prints newline, word, and byte counts for files.
    • Example: wc filename (displays the line, word, and byte count of filename).

Searching and Sorting

  1. grep
    • Usage: Searches text using patterns.
    • Example: grep 'pattern' filename (searches for pattern in filename).
  2. sort
    • Usage: Sorts lines of text files.
    • Example: sort filename (sorts the lines in filename).

Manual Pages

  • man
  • Usage: Displays the manual page for a command.
  • Example: man ls (shows the manual for the ls command).

Networking and Connectivity

  1. ping
    • Usage: Checks the network connection to a server.
    • Example: ping example.com (sends ICMP ECHO_REQUEST to network hosts).
  2. ifconfig
    • Usage: Configures network interfaces.
    • Example: ifconfig eth0 (displays the configuration of eth0).
  3. wget
    • Usage: Downloads files from the internet.
    • Example: wget http://example.com/file (downloads file from the specified URL).
  4. curl
    • Usage: Transfers data from or to a server.
    • Example: curl http://example.com (retrieves the content from the URL).

System Information

  1. uname
    • Usage: Prints system information.
    • Example: uname -a (displays all system information).
  2. df
    • Usage: Reports file system disk space usage.
    • Example: df -h (shows disk space in human-readable format).
  3. du
    • Usage: Estimates file space usage.
    • Example: du -sh directory (displays the total size of the directory).
  4. top
    • Usage: Displays tasks and system status.
    • Example: top (shows an ongoing view of system processes).
  5. ps
    • Usage: Reports a snapshot of current processes.
    • Example: ps aux (displays detailed information about all running processes).
  6. uptime
    • Usage: Tells how long the system has been running.
    • Example: uptime (displays the current time, uptime, number of users, and load averages).

User and Permission Management

  1. chmod
    • Usage: Changes file permissions.
    • Example: chmod 755 filename (sets the permissions of filename to 755).
  2. chown
    • Usage: Changes file owner and group.
    • Example: chown user:group filename (changes the owner and group of filename).
  3. passwd
    • Usage: Changes a user’s password.
    • Example: passwd (prompts to change the current user’s password).
  4. useradd
    • Usage: Creates a new user.
    • Example: useradd newuser (creates a new user named newuser).
  5. usermod
    • Usage: Modifies a user account.
    • Example: usermod -aG groupname username (adds username to groupname).
  6. userdel
    • Usage: Deletes a user account.
    • Example: userdel username (deletes the user username).

Package Management (Debian-based systems)

  1. apt-get
    • Usage: Handles packages.
    • Example: apt-get update (updates the package lists).
  2. apt-cache
    • Usage: Searches for packages.
    • Example: apt-cache search package_name (searches for package_name).
  3. dpkg
    • Usage: Handles individual package files.
    • Example: dpkg -i package.deb (installs package.deb).

Process Management

  1. kill
    • Usage: Terminates processes.
    • Example: kill PID (sends a signal to terminate the process with PID).
  2. killall
    • Usage: Kills processes by name.
    • Example: killall processname (terminates all instances of processname).
  3. pkill
    • Usage: Kills processes by name or attribute.
    • Example: pkill -u username (kills all processes owned by username).

Text Processing

  1. awk
    • Usage: Pattern scanning and processing language.
    • Example: awk '{print $1}' filename (prints the first column from filename).
  2. sed
    • Usage: Stream editor for filtering and transforming text.
    • Example: sed 's/old/new/g' filename (replaces old with new in filename).
  3. tr
    • Usage: Translates or deletes characters.
    • Example: echo "text" | tr 'a-z' 'A-Z' (converts lowercase to uppercase).
  1. echo
    • Usage: Displays a line of text.
    • Example: echo "Hello, World!" (prints Hello, World! to the terminal).
  2. date
    • Usage: Displays or sets the system date and time.
    • Example: date (shows the current date and time).
  3. history
    • Usage: Displays the command history.
    • Example: history (shows the list of previously executed commands).
  4. clear
    • Usage: Clears the terminal screen.
    • Example: clear (clears the screen).

File Manipulation

  1. head
    • Usage: Displays the beginning of a file.
    • Example: head -n 10 filename (shows the first 10 lines of filename).
  2. diff
    • Usage: Compares files line by line.
    • Example: diff file1 file2 (compares file1 and file2).
  3. cmp
    • Usage: Compares two files byte by byte.
    • Example: cmp file1 file2 (checks if file1 and file2 are identical).

Disk Usage and Management

  1. fdisk
    • Usage: Manipulates disk partition table.
    • Example: fdisk /dev/sda (opens fdisk to manage partitions on /dev/sda).
  2. mount
    • Usage: Mounts a filesystem.
    • Example: mount /dev/sda1 /mnt (mounts /dev/sda1 to /mnt).
  3. umount
    • Usage: Unmounts a filesystem.
    • Example: umount /mnt (unmounts the filesystem mounted at /mnt).

Archive Manipulation

  1. zip
    • Usage: Compresses files into a ZIP archive.
    • Example: zip archive.zip file1 file2 (creates archive.zip containing file1 and file2).
  2. unzip
    • Usage: Extracts files from a ZIP archive.
    • Example: unzip archive.zip (extracts the contents of archive.zip).

System Monitoring

  1. htop
    • Usage: An interactive process viewer (similar to top but more user-friendly).
    • Example: htop (opens the interactive process viewer).
  2. iostat
    • Usage: Reports CPU and I/O statistics.
    • Example: iostat (displays I/O statistics).
  3. vmstat
    • Usage: Reports virtual memory statistics.
    • Example: vmstat (displays virtual memory statistics).

Permissions and Ownership

  1. chgrp
    • Usage: Changes the group ownership of files.
    • Example: chgrp groupname filename (changes the group of filename to groupname).
  2. umask
    • Usage: Sets the default file creation permissions.
    • Example: umask 022 (sets the default file creation permissions to 755).

Process Control

  1. bg
    • Usage: Resumes a suspended job in the background.
    • Example: bg %1 (resumes job number 1 in the background).
  2. fg
    • Usage: Brings a background job to the foreground.
    • Example: fg %1 (brings job number 1 to the foreground).

SSH and Remote Management

  1. ssh
    • Usage: Connects to a remote machine securely.
    • Example: ssh user@hostname (connects to hostname as user).
  2. scp
    • Usage: Securely copies files between hosts.
    • Example: scp file user@hostname:/path (copies file to /path on hostname).
  3. rsync
    • Usage: Synchronizes files and directories between two locations.
    • Example: rsync -avz source destination (synchronizes source to destination).

Cron Jobs

  1. crontab
    • Usage: Schedules periodic background tasks.
    • Example: crontab -e (edits the current user’s cron jobs).

Text Editors

  1. nano
    • Usage: A simple text editor.
    • Example: nano filename (opens filename in the nano editor).
  2. vi / vim
    • Usage: A powerful text editor.
    • Example: vi filename (opens filename in the vi editor).

Other Useful Commands

  1. xargs
    • Usage: Builds and executes command lines from standard input.
    • Example: echo file1 file2 | xargs rm (removes file1 and file2).
  2. tee
    • Usage: Reads from standard input and writes to standard output and files.
    • Example: echo "text" | tee file (writes text to file and displays it).
  3. nohup
    • Usage: Runs a command immune to hangups.
    • Example: nohup command & (runs command in the background and allows it to continue running after logging out).
  4. watch
    • Usage: Executes a program periodically and displays output.
    • Example: watch -n 1 df -h (runs df -h every second).
  5. basename
    • Usage: Strips directory and suffix from filenames.
    • Example: basename /path/to/file (returns file).
  6. dirname
    • Usage: Strips the last component from file names.
    • Example: dirname /path/to/file (returns /path/to).
  7. file
    • Usage: Determines the file type.
    • Example: file filename (displays the type of filename).

Advanced File Operations

  1. split
    • Usage: Splits a file into pieces.
    • Example: split -b 1M largefile (splits largefile into 1MB chunks).
  2. shred
    • Usage: Securely deletes a file by overwriting it.
    • Example: shred -u filename (overwrites and deletes filename).

Advanced Text Processing

  1. cut
    • Usage: Removes sections from each line of files.
    • Example: cut -d':' -f1 /etc/passwd (displays the first field of /etc/passwd).
  2. paste
    • Usage: Merges lines of files.
    • Example: paste file1 file2 (merges lines of file1 and file2).
  3. uniq
    • Usage: Reports or omits repeated lines.
    • Example: uniq filename (removes duplicate lines from filename).
  4. join
    • Usage: Joins lines of two files on a common field.
    • Example: join file1 file2 (joins lines of file1 and file2 with a common field).

Disk and File System Management

  1. fsck
    • Usage: Checks and repairs a Linux file system.
    • Example: fsck /dev/sda1 (checks and repairs the file system on /dev/sda1).
  2. mkfs
    • Usage: Builds a Linux file system.
    • Example: mkfs -t ext4 /dev/sda1 (creates an ext4 file system on /dev/sda1).
  3. blkid
    • Usage: Locates and prints block device attributes.
    • Example: blkid (displays attributes of all block devices).
  4. lsblk
    • Usage: Lists information about block devices.
    • Example: lsblk (displays block devices).

System Performance

  1. nice
    • Usage: Runs a command with modified scheduling priority.
    • Example: nice -n 10 command (runs command with a niceness of 10).
  2. renice
    • Usage: Alters the priority of running processes.
    • Example: renice 10 -p PID (changes the priority of the process with PID to 10).
  3. dstat
    • Usage: Versatile resource statistics.
    • Example: dstat (provides a detailed view of system resource usage).

Networking

  1. netstat
    • Usage: Prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
    • Example: netstat -tuln (displays listening ports).
  2. traceroute
    • Usage: Prints the route packets take to the network host.
    • Example: traceroute example.com (shows the route to example.com).
  3. nslookup
    • Usage: Queries Internet name servers interactively.
    • Example: nslookup example.com (looks up the IP address for example.com).
  4. iptables
    • Usage: Administers IP packet filter rules.
    • Example: iptables -L (lists all current rules).
  5. nmap
    • Usage: Network exploration tool and security scanner.
    • Example: nmap -sP 192.168.1.0/24 (scans the network for active devices).

Backup and Restore

  1. rsnapshot
    • Usage: Filesystem snapshot utility.
    • Example: rsnapshot hourly (creates an hourly snapshot).
  2. dd
    • Usage: Converts and copies a file.
    • Example: dd if=/dev/sda of=/path/to/backup.img (creates a disk image of /dev/sda).

File Integrity

  1. md5sum
    • Usage: Computes and checks MD5 hash.
    • Example: md5sum filename (outputs the MD5 hash of filename).
  2. sha256sum
    • Usage: Computes and checks SHA-256 hash.
    • Example: sha256sum filename (outputs the SHA-256 hash of filename).

Scripting and Automation

  1. cron
    • Usage: Daemon to execute scheduled commands.
    • Example: crontab -l (lists the cron jobs).
  2. at
    • Usage: Schedules commands to run at a particular time.
    • Example: echo "command" | at now + 5 minutes (schedules command to run in 5 minutes).

System Logs

  1. dmesg
    • Usage: Prints the message buffer of the kernel.
    • Example: dmesg (displays kernel messages).
  2. journalctl
    • Usage: Queries and displays messages from the journal.
    • Example: journalctl -xe (shows the system log with detailed output).
  3. logrotate
    • Usage: Rotates, compresses, and mails system logs.
    • Example: logrotate /etc/logrotate.conf (runs the logrotate configuration).

Virtualization and Containers

  1. docker
    • Usage: Manages Docker containers.
    • Example: docker ps (lists running Docker containers).
  2. vagrant
    • Usage: Builds and manages virtual machine environments.
    • Example: vagrant up (starts the Vagrant environment).

Miscellaneous

  1. screen
    • Usage: Terminal multiplexer that allows for multiple sessions within a single terminal window.
    • Example: screen (starts a new screen session).
  2. tmux
    • Usage: Terminal multiplexer that lets you switch between several programs in one terminal.
    • Example: tmux (starts a new tmux session).
  3. bc
    • Usage: Command-line calculator.
    • Example: echo "scale=2; 3/7" | bc (calculates 3/7 to two decimal places).
  4. expr
    • Usage: Evaluates expressions.
    • Example: expr 1 + 2 (returns 3).

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *