Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
samikshakute authored Aug 20, 2023
1 parent a673132 commit 5e60ca3
Showing 1 changed file with 143 additions and 56 deletions.
199 changes: 143 additions & 56 deletions commands/README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,75 @@
# Bash commands

- <b> List Operations: </b>
- `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. </br>

- <b> Directory Operations: </b>
- `open .` - opens current directory in files
- `pwd` - displays the present working directory
- `mkdir <dir-name>` - creates a new directory.
- `mkdir <dir1-name> <dir2-name>` - creates a new directory in existing directory.
- `mkdir -p <dir1-name> <dir2-name> <dir3-name>` - creates a new directory in between existing directories.
- `cd folder-name`
- `cd` - go to home directory
- `cd ..` - go back </br>
. 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 <dir-name>` - to remove an empty directory.
- `rmdir -rf <dir-name>` - removes a non-empty directory.
- `find .` - find in current directory.
- `find ..` - find in previous directory.
- `find <folder-name>` - 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 <file-name>`
- <b> Basic Operations:</b>
- 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 </br>
. 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. </br>
- `tree` - Displays a tree view of the filesystem.
- `tree -d` - Displays directories only.
- Hard and Soft Links:
- `ln <source> <destination>` - Used to create hard links.
- `ln -s <source> <destination>` - Used to create soft(symbolic) links.

- Navigating the directory history:
- `pushd <directory>` - Used to change the current directory and also save the current directory onto the directory stack.
- `popd <directory>` - 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.

- <b> File Operations: </b>
- `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 <file>` - 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 <file-name>` - Displays the first 10 lines of file.
- `head -4 <file-name>` - Displays the first 4 lines of file.
- `tail <file-name>` - Displays the last 10 lines of file by default.
- `tail -2 <file-name>` - Displays last 2 lines of file by default.
- `touch <file-name>` - Creates a new file.
- `touch <folder-name>/<file-name>` - Creates a file in a folder.
- `echo > <file-name>` - Creates a new file
- `mv <file1-name> <file2-name>` - Renames file1-name to file2-name.
- `mv <file-name> <dir-name>` - Moves file into directory.
- `mv <file-name ../<newFile-name>` - Move and create a new file in previous directory.
- `rm <file-name>` - Removes a file permanently.
- `rm -f <file-name>` - Forces deletion of file in certain scenarios when the file is unable to delete. For example, if the file is open, etc.
- `rm -i <file-name>` - 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 <file-name>` - Forcefully remove a directory recursively.
- `locate <file-name>` - 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 <file-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.


- <b> File Operations: </b>
- `touch <file-name>` - creates a new file.
- `touch <folder-name>/<file-name>` - creates a file in a folder.
- `cp <file1-name> <file2-name>` - copy file1 contents in file2.
- `mv <file1-name> <file2-name>` - renames file1-name to file2-name.
- `mv <file-name> <dir-name>` - moves file into directory.
- `mv <file-name ../<newFile-name>` - move and create a new file in previous directory.
- `rm <file-name>` - removes a file permanently.
- `rm -f <file-name>` - forces deletion of file in certain scenarios when the file is unable to delete. For example, if the file is open, etc.
- `head <file-name>` - displays the first 10 lines of file.
- `head -n 4 <file-name>` - displays the first 4 lines of file.
- `tail <file-name>` - displays the last 10 lines of file.
- `tail -n 2 <file-name>` - 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 <file1-name> <file2-name>` - copy file1 contents in file2.

- `diff <file1-name> <file2-name>` - compares the contents of two file line by line and outputs the lines that do not match.
- `locate <file-name>` - locates the file.
- `locate ".txt"` - displays all the files that end with an extension of .txt

- `sort <file-name>` - sorts alphabetically.
- `-r` - sorts in reverse order
- `-f` - case insensitive sorting
Expand All @@ -62,8 +79,9 @@
- `join <file1-name> <file2-name>` - combines lines from two files based on a common field or key.
- Zipping files: `zip <zip-file-name> <file1-name> <file2-name>`
- Unzipping files: `unzip <file-name>`
- `cut -c 1-2 <file-name>` - shows first 2 columns of file.
- `whereis` - locates and displays source of file.
- `cut -c 1-2 <file-name>` - 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 <file/directory-name>` - To find the type of files/directories.

- `cat <file-name>` - displays contents of file.
Expand All @@ -79,10 +97,46 @@
- `sed 's/pattern/replacement/' filename` - searches for pattern in file and replaces them with the given replacement text.
- `wc <file>` - prints the number of lines, words and characters in file.
- `-l` - prints just the number of lines.

- <b> Directory Operations: </b>
- `open .` - opens current directory in files
- `pwd` - displays the present working directory
- `mkdir <dir-name>` - creates a new directory.
- `mkdir <dir1-name> <dir2-name>` - creates a new directory in existing directory.
- `mkdir -p <dir1-name> <dir2-name> <dir3-name>` - creates a new directory in between existing directories.
- `cd folder-name`
- `cd` - go to home directory
- `cd ..` - go back </br>
. 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 <dir-name>` - to remove an empty directory.
- `rmdir -rf <dir-name>` - removes a non-empty directory.
- `find .` - find in current directory.
- `find ..` - find in previous directory.
- `find <folder-name>` - find in folder.

- <b> Environmental Variables: </b>
- `env` - displays environmental variables


- <b> Processes: </b>
- `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.

- <b> Text Editors: </b>
- `nano <file>` - start the editor and edit file.
- `gedit <file>` - start the text editor and edit file.
Expand Down Expand Up @@ -114,8 +168,6 @@
- `getent group <user-name>` - to check user exists or not
- `lsof` - shows all open files.
- `lsof -u <user-name>` - shows open files for particular user.
- `ps aux` - shows processess running.


- <b> Permissions:<br> </b>
There are three types of permissions: **read, write and execute** and there are three types of owners: **user, group and others.**
Expand Down Expand Up @@ -165,7 +217,29 @@
- `nslookup <url/IP address>` - to check IP address for particular domain.
- `netstat` - shows all active ports
- `telnet`


- <b> Finding Documentation: </b>
- `man command_name` - To view the manual page of a specific command.
- `man -f <command_name>` - To list all pages on the topic. Generates the same result as typing `whatis`.
- `man -k <command_name>` - 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 <command_name>` - Used to display the manual pages for a specified command from all available manual page sections.
- `info <topic name>` - To view help for a particular topic. The system then searches for the topic in all available info files.
- `<command_name> --help` - Help provides basic information about shell commands.

- <b> Basic Packaging Commands(deb): </b>
- `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?

- <b> Basic shortcuts: </b>
- `CTRL-L` - Clears the screen
- `CTRL-D` - Exits the current shell
Expand All @@ -186,13 +260,26 @@
Example: `git init;git add .;git commit -m "message";git push`
- `!!(bang bang)` - executes previous command.

- <b> Operators: </b>
- <b> Operators</b>
- 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 !(<file-name>)`
- `>>` - use to append contents. example: `"hey" >> <file-name>` file will contain hey.
- `>` - use to overwrite.
- `\` - used to split long commands and execute them as single command.
- `{}` - combination operator use to group commands. </br>

- <b> Wildcards </b>
- `?` - 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.

0 comments on commit 5e60ca3

Please sign in to comment.