From 5e60ca39964dd1c818d5393067212177f72bc997 Mon Sep 17 00:00:00 2001 From: Samiksha Kute Date: Sun, 20 Aug 2023 10:25:38 +0530 Subject: [PATCH] Update README.md --- commands/README.md | 199 ++++++++++++++++++++++++++++++++------------- 1 file changed, 143 insertions(+), 56 deletions(-) diff --git a/commands/README.md b/commands/README.md index 0d928b2..8fa9b02 100644 --- a/commands/README.md +++ b/commands/README.md @@ -1,58 +1,75 @@ # Bash commands - - - List Operations: - - `ls` - shows list of files and directories. - - `ls -l` - shows users, permissions, group owners, etc. - - `ls -a` - also shows hidden files. - - `ls -al` - combination of ls -a and ls -l - - `ls -R` - also shows files in sub directories.
- - - Directory Operations: - - `open .` - opens current directory in files - - `pwd` - displays the present working directory - - `mkdir ` - creates a new directory. - - `mkdir ` - creates a new directory in existing directory. - - `mkdir -p ` - creates a new directory in between existing directories. - - `cd folder-name` - - `cd` - go to home directory - - `cd ..` - go back
- . means current directory and .. means previous directory - - `cd ../folder-name` --> in the previous directory there is another directory. - - `rm -r folder-name` - removes a folder permanently. - - `rmdir ` - to remove an empty directory. - - `rmdir -rf ` - removes a non-empty directory. - - `find .` - find in current directory. - - `find ..` - find in previous directory. - - `find ` - find in folder. - - `find . -type d` - displays files in current directory of type directory. - - `find . -type f` - displays files in current directory of type file. - - `find . -type f -name ` + - Basic Operations: + - Locating Applications: + - `which [command]` - Locates and displays source of file + - `whereis [command]` - Locates and displays source of file. It also looks for packages in a broader range of system directories. + - Accessing Directories: + - `pwd` - Displays the present working directory. + - `cd` - Go to home directory + - `cd ..` - Go back
+ . means current directory and .. means previous directory + - `cd ../folder-name` --> In the previous directory there is another directory. + - `cd -` - Change to previous working directory; - (minus) + - Exploring the File System: + - `cd /` - Changes your current directory to the root (/) directory (or path you supply). + - `ls` - List the contents of the present working directory. + - `ls -a` - List all files, including hidden files and directories (those whose name start with . ) + - `ls -l` - Shows users, permissions, group owners, etc. + - `ls -li /path/to/directory` - Used to list files and directories in a directory. The -l option provides a long listing format, and the -i option displays the inode number of each file. + - `ls -l *pattern*` - Used to list all files and directories in the current directory that match the specified pattern. + - `ls -al` - Combination of ls -a and ls -l + - `ls -R` - Also shows files in sub directories.
+ - `tree` - Displays a tree view of the filesystem. + - `tree -d` - Displays directories only. + - Hard and Soft Links: + - `ln ` - Used to create hard links. + - `ln -s ` - Used to create soft(symbolic) links. + + - Navigating the directory history: + - `pushd ` - Used to change the current directory and also save the current directory onto the directory stack. + - `popd ` - Used to remove the top directory from the directory stack and change the current directory to the one that was removed from the stack. + - `dirs` - Displays the directories in the directory stack in reverse order, with the most recent directory listed first. + + - File Operations: + - `cat` - Used for viewing files that are not very long; it does not provide any scroll-back. + - `cat -n` - Also displays the line numbers. + - `wc ` - Prints the number of lines, words and characters in file. + - `tac`- Used to look at a file backwards, starting with the last line. + - `less` - Used to view larger files because it is a paging program. It pauses at each screen full of text, provides scroll-back capabilities, and lets you search and navigate within the file. + + *NOTE: Use / to search for a pattern in the forward direction and ? for a pattern in the backward direction. An older program named more is still used, but has fewer capabilities: "less is more".* + - `head ` - Displays the first 10 lines of file. + - `head -4 ` - Displays the first 4 lines of file. + - `tail ` - Displays the last 10 lines of file by default. + - `tail -2 ` - Displays last 2 lines of file by default. + - `touch ` - Creates a new file. + - `touch /` - Creates a file in a folder. + - `echo > ` - Creates a new file + - `mv ` - Renames file1-name to file2-name. + - `mv ` - Moves file into directory. + - `mv ` - Move and create a new file in previous directory. + - `rm ` - Removes a file permanently. + - `rm -f ` - Forces deletion of file in certain scenarios when the file is unable to delete. For example, if the file is open, etc. + - `rm -i ` - Used to remove (delete) files and directories from the file system. The system will display a prompt for each item, asking you to confirm whether you want to delete it. You can then respond with "y" (yes) or "n" (no). + - `rm -rf ` - Forcefully remove a directory recursively. + - `locate ` - locates the file. + - `locate ".txt"` - displays all the files that end with an extension of .txt + - `find . -type d` - displays files in current directory of type directory. + - `find . -type f` - displays files in current directory of type file. + - `find . -type f -name ` - `-type f -name f*` - shows files starting with f. - `-type f -name "*.txt"` - shows files of type .txt - `-type f -iname "*.txt"` - shows files of type .txt that are not case sensitive. - `-type f -mmin -20` - displays files that were modified less than 20 min ago. - `-type f -mmin +20` - displays files that were modified more than 20 min ago. - `-type f -maxdepth 2` - - - `find . -size +1k` - shows files/folders with size greater than 1kb. - - `find . -empty` - shows files that are empty. - - - - File Operations: - - `touch ` - creates a new file. - - `touch /` - creates a file in a folder. - - `cp ` - copy file1 contents in file2. - - `mv ` - renames file1-name to file2-name. - - `mv ` - moves file into directory. - - `mv ` - move and create a new file in previous directory. - - `rm ` - removes a file permanently. - - `rm -f ` - forces deletion of file in certain scenarios when the file is unable to delete. For example, if the file is open, etc. - - `head ` - displays the first 10 lines of file. - - `head -n 4 ` - displays the first 4 lines of file. - - `tail ` - displays the last 10 lines of file. - - `tail -n 2 ` - displays last 2 lines of file. + - `find . -size +1k` - shows files/folders with size greater than 1kb. + - `find . -empty` - shows files that are empty. + + - - `cp ` - copy file1 contents in file2. + - `diff ` - compares the contents of two file line by line and outputs the lines that do not match. - - `locate ` - locates the file. - - `locate ".txt"` - displays all the files that end with an extension of .txt + - `sort ` - sorts alphabetically. - `-r` - sorts in reverse order - `-f` - case insensitive sorting @@ -62,8 +79,9 @@ - `join ` - combines lines from two files based on a common field or key. - Zipping files: `zip ` - Unzipping files: `unzip ` - - `cut -c 1-2 ` - shows first 2 columns of file. - - `whereis` - locates and displays source of file. + - `cut -c 1-2 ` - shows first 2 columns of file. + - `which [command]` - locates and displays source of file + - `whereis [command]` - locates and displays source of file. It also looks for packages in a broader range of system directories. - `file ` - To find the type of files/directories. - `cat ` - displays contents of file. @@ -79,10 +97,46 @@ - `sed 's/pattern/replacement/' filename` - searches for pattern in file and replaces them with the given replacement text. - `wc ` - prints the number of lines, words and characters in file. - `-l` - prints just the number of lines. + + - Directory Operations: + - `open .` - opens current directory in files + - `pwd` - displays the present working directory + - `mkdir ` - creates a new directory. + - `mkdir ` - creates a new directory in existing directory. + - `mkdir -p ` - creates a new directory in between existing directories. + - `cd folder-name` + - `cd` - go to home directory + - `cd ..` - go back
+ . means current directory and .. means previous directory + - `cd ../folder-name` --> in the previous directory there is another directory. + - `rm -r folder-name` - removes a folder permanently. + - `rmdir ` - to remove an empty directory. + - `rmdir -rf ` - removes a non-empty directory. + - `find .` - find in current directory. + - `find ..` - find in previous directory. + - `find ` - find in folder. - Environmental Variables: - `env` - displays environmental variables - + + - Processes: + - `ps` - Displays information about processes currently running on the system. + - `ps aux` - Shows a detailed list of all running processes. + - `ps -e` - Lists all processes. + - `ps -ef` - Provides a full listing with additional details. + - `ps -eLf` - Displays one line of information for every thread. + - `pstree` - Displays the processes running on the system in the form of a tree diagram showing the relationship between a process and + its parent process and any other processes that it created. + - `top` - Provides an interactive real-time view of system processes. + - `htop` - Enhanced version with a more user-friendly interface and additional features. + - `pidstat` - Reports statistics for processes, including CPU, memory, and I/O usage. + - `vmstat` - Provides information about system-wide virtual memory statistics and can offer insights into process behavior. + - `iotop` - Monitors I/O usage by processes and helps identify processes causing high I/O loads. + - `w` - Displays information about currently logged-in users, their activities, and system load. + - `top` - Provides a dynamic real-time view of system processes and resource usage. provides a dynamic real-time view of system processes + and resource usage. + - `uptime` - Provides a summary of system uptime and load averages. + - Text Editors: - `nano ` - start the editor and edit file. - `gedit ` - start the text editor and edit file. @@ -114,8 +168,6 @@ - `getent group ` - to check user exists or not - `lsof` - shows all open files. - `lsof -u ` - shows open files for particular user. - - `ps aux` - shows processess running. - - Permissions:
There are three types of permissions: **read, write and execute** and there are three types of owners: **user, group and others.** @@ -165,7 +217,29 @@ - `nslookup ` - to check IP address for particular domain. - `netstat` - shows all active ports - `telnet` - + + - Finding Documentation: + - `man command_name` - To view the manual page of a specific command. + - `man -f ` - To list all pages on the topic. Generates the same result as typing `whatis`. + - `man -k ` - To list all pages that discuss a specific topic (even if the specified subject is not present in the name). Generates the same result as typing `apropos`. + - `man -a ` - Used to display the manual pages for a specified command from all available manual page sections. + - `info ` - To view help for a particular topic. The system then searches for the topic in all available info files. + - ` --help` - Help provides basic information about shell commands. + + - Basic Packaging Commands(deb): + - `dpkg --install foo.deb` - Install package. + - `apt install foo` - Install package, dependencies. + - `dpkg --remove foo.deb` - Remove package. + - `apt autoremove foo` - Remove package, dependencies. + - `dpkg --install foo.deb` - Update package. + - `apt install foo` - Update package, dependencies. + - `apt dist-upgrade` - Update entire system. + - `dpkg --list` - Show all installed packages. + - `dpkg --listfiles foo` - Get information on package. + - `dnf list "foo" apt-cache search foo` - Show packages named foo. + - `apt-cache dumpavail foo` - Show all available packages. + - `dpkg --search file` - What package is file part of? + - Basic shortcuts: - `CTRL-L` - Clears the screen - `CTRL-D` - Exits the current shell @@ -186,13 +260,26 @@ Example: `git init;git add .;git commit -m "message";git push` - `!!(bang bang)` - executes previous command. - - Operators: + - Operators + - I/O Redirection: + - `>` - Redirects standard output to a file, overwriting the file if it already exists. + - `>>` - Redirects standard output to a file, appending the output to the file if it already exists. + - `<` - Redirects standard input from a file. + - `2>` - Redirects standard error to a file. + - `2>>` - Redirects standard error to a file, appending to the file if it already exists. + - `&>` - Redirects both standard output and standard error to a file. + - `|` - Redirects the output of one command as input to another command (pipeline). + - `&` - it will create a process in the background so that other commands can be running. We can check the background process using `ps` command and kill it if needed. Example: `ping google.com & facebook.com` - `&&` - The command that is succeeding this operator will only execute when the previous one is finish executing. Example: `echo "first" && "second"` - `||` - The command that is after the OR operator will only execute if the execution of previous command fails. Example: `echo "first" || echo "second"` - `!` - can be use to delete all the files except one particular file. Example: `rm -rf !()` - - `>>` - use to append contents. example: `"hey" >> ` file will contain hey. - - `>` - use to overwrite. - `\` - used to split long commands and execute them as single command. - `{}` - combination operator use to group commands.
+ + - Wildcards + - `?` - Matches any single character. + - `*` - Matches any string of characters. + - `[set]` - Matches any character in the set of characters, for example [adf] will match any occurrence of a, d, or f. + - `[!set]` - Matches any character not in the set of characters.