Salta al contenuto principale

Linux bash commands

This is a list of the more important Linux Bash commands for beginning Linux users. It isn't intended to be complete, but it's a good starting point.

Most useful Linux Bash commands

ls: list directory contents
Example: ls -l (Displays detailed list of files and directories)

cd: change directory
Example: cd /home/user (Changes the current directory to /home/user)

pwd: print name of current/working directory
Example: pwd (Displays the full path of the current directory)

who: show who is logged on
Example: who (Lists all users currently logged in)

whoami: print effective userid
Example: whoami (Displays the current logged-in username)

nano: Nano's ANOther editor, an enhanced free Pico clone - text editor
Example: nano filename.txt (Opens filename.txt in Nano editor)

more: file perusal filter for CRT viewing - visualize text files in shell
Example: more filename.txt (Displays the content of filename.txt one screen at a time)

less: opposite of more - more user-friendly text viewer
Example: less filename.txt (Displays the content of filename.txt with navigation options)

cat: concatenate files and print on the standard output
Example: cat file1.txt file2.txt (Displays the contents of file1.txt and file2.txt)

find: search for files in a directory hierarchy
Example: find /home -name "*.txt" (Finds all .txt files in the /home directory)

cp: copy files and directories
Example: cp source.txt destination.txt (Copies source.txt to destination.txt)

mv: move (rename) files
Example: mv oldname.txt newname.txt (Renames oldname.txt to newname.txt)

rm: remove files or directories
Example: rm filename.txt (Deletes filename.txt)

rmdir: remove empty directories
Example: rmdir directory (Deletes the specified empty directory)

touch: change file timestamps
Example: touch newfile.txt (Creates an empty file named newfile.txt)

su: change user ID
Example: su - username (Switches to the specified user account)

ln: make links between files
Example: ln -s source.txt link.txt (Creates a symbolic link named link.txt to source.txt)

fsck: check and repair a Linux file system
Example: fsck /dev/sda1 (Checks and repairs the file system on /dev/sda1)

fdisk: manipulate disk partition table
Example: fdisk /dev/sda (Starts partition table manipulation for /dev/sda)

cfdisk: display or manipulate a disk partition table - more friendly than fdisk
Example: cfdisk /dev/sda (Starts a user-friendly partition table manipulation for /dev/sda)

parted: a partition manipulation program - GPT capable
Example: parted /dev/sda (Starts the parted tool for /dev/sda)

mount: mount a file system
Example: mount /dev/sda1 /mnt (Mounts the file system on /dev/sda1 to /mnt)

df: report file system disk space usage
Example: df -h (Displays disk space usage in a human-readable format)

uname: print system information
Example: uname -a (Displays all system information)

Understanding Output Redirection on Linux

Output redirection on Linux allows you to control where the output of a command is sent. By default, the output is displayed on the screen, but you can redirect it to files or other commands using operators.

Examples:
command > file.txt: Redirects the standard output of the command to file.txt, creating or overwriting it if it exists.
command >> file.txt: Appends the standard output of the command to file.txt if it exists, or creates it if it doesn't.
command 2> error.log: Redirects the standard error output of the command to error.log.
command &> output.log: Redirects both standard output and standard error to output.log.
command | another_command: Uses a pipe | to send the output of one command as input to another command.

These techniques are essential for effective shell scripting and managing command outputs on Linux, but can be used create an image of Hard Disk much more

Share is Care!

If you liked this page, please share it, I will be so proud!

Aggiungi un commento

Comment

  • Elementi HTML permessi: <br> <p> <code class="language-*"> <pre>
  • Linee e paragrafi vanno a capo automaticamente.
  • Solo le immagini ospitate su questo sito possono essere utilizzate nel tag <img>.