List files and folders in the current directory.
Parameters:
- –l to list the content as a detailed list
- -a display all files (hidden + non-hidden)
- -r reverses the sorting order for the displayed files and directories
- -s sorts the output by file size
- -t sorts the output by file modification time
Example of input: ls -la
Shows current directory
- -L prints the symbolic path
- -P prints the actual path
Example of input: pwd
Change directory from the current directory to another one.
- ~ back to main directory
- .. move to the parent directory
Example of input: cd /home
The touch command is used to create an empty file.
Parameters:
- –t creates file followed by the time with the following format YYYYMMDDHHMM
- -a changes file access and modification time
- -c does't create n empty file
Example of input: touch -t 202012011200 test1
You can easily delete single files
- –i will ask before deleting each file
- –r will recursively delete a directory and all its contents (normally rm will not delete directories, while rmdir will only delete empty directories)
Example of input: rm name
Copy the source to target.
Parameters:
- –i interactive mode means waiting for the confirmation if there are files on the target, it will be overwritten
- -r recursive copy means include subdirectories if they found
- -u оverwrites the destination file only if the source file is newer than the destination file
Example of input: cp –ir sourcedir targetdir
Move the source to target and remove the source.
Parameters:
- –i interactive mode means to wait for the confirmation if there are files on the target, it will be overwritten
- –f does not prompt you before overwriting an existing file
Example of input: mv –i sourceFile targetFile
Delete file or directory, and you must use –r in case you want to delete a directory.
Parameters:
- –r recursive delete means delete all subdirectories if found
- -i interactive means wait till confirmation
Example of input: rm –r anotherDir/
Create a new directory.
- -v prints a message for each created directory
- -m set file mode
Example of input: mkdir NewDir
Delete a directory.
- -p removes the directory, including all its ancestors
- -v displays verbose information for every directory
Example of input: rmdir NewDir/
Change the owner of a file or directory.
Parameters:
- –R capital R here means to change ownership of all subdirectories if found, and you must use this parameter if you use the command against a directory
- -f suppresses all error messages except usage messages
Example of input: chown –R root:root myDir
Change the permission of a file or directory.
Parameters:
- The mode which consists of 3 parts, owner, group, and others means what will be the permissions for these modes, and you must specify them The permission is one of the followings:
Read =4
Write = 2
Execute =1
Every permission represented by a number as shown, and you can combine permissions.
Example of input: chmod 755 myfile
That means set permission for the file named myfile as follows: owner: set it to 7, which means 4+2+1 means read+write+execute. group: set it to 5, which means 4+1 means read+execute. other: set it to 5, which means 4+1 means read+execute. Note: execute for a folder, means opening it.To find a file in your system, the locate command will search the system for the pattern you provide..
Example of input: locate myfile
Simply prints today’s date. Just type date on the shell.
- -I displays the date and time in ISO 8601 format
Example of input: date
Finds all files with flags you provided.
- -type filter by file type
- -name filter by file name
Example of input: find . -type f -name "*.txt"
Used to display line of text/string that are passed as an argument.
- -n used to omit echoing trailing newline
- -e enables the interpretation of backslash escapes
Example of input: echo "Hello, world!"
Displays the disk space used in the file system.
- –h displays space in gb and mb
- -c displays the output in colon separated format
Example of input: df"
Combines several files into an archive and compression if you want.
- –c create a new archive
- -z compress the archive using gzip package
- -j compress the archive using the bzip2 package
- -v verbose mode means showing the processed files
- -f write the output to a file and not to screen
- -x unpack files from an archive
Example of input: tar –czvf myfiles.tar.gz myfiles
This command will pack and compress all files in folder myfiles to a compressed archive named myfiles.tar.gz.Example of input: tar-xzvf myfiels.tar.gz
This command will decompress the archive.Displays file content to screen without limits.
- -n displays line numbers in front of each line in a file
- -b removes the empty lines
- -е displays a '$' sign at the end of every line
Example of input: cat myfile.txt
Output the end of a file
- -n num prints the last ‘num’ lines instead of last 10 lines
Example of input: tail test.txt
Command is used to view the text files in the command prompt.
- –p clears the screen and then displays the text
- -n option displays the line numbers at the beginning of each line
- –s squeezes multiple blank lines into one single blank line
Example of input: more -p sample.txt
Displays file content with a scroll screen so you can navigate between pages using PgUp, PgDn, Home, and End.
Example of input: less myfile
- –n prints a specific number of lines from the beginning of a file
- –c prints a specific number of bytes from the beginning of a file
- –v data from the specified file is always preceded by its file name
Example of input: head -n 5 sample.txt
Searches for a string in the specified files and displays which line contains the matched string.
- –R recursive search inside subdirectories if found
- -i insensitive search and ignore case
- -l displays file name, not the text lines
Example of input: grep "print" main.py
Allows you to compare two files line by line.
- –c allows you to view additional information related to the specified files and the changes needed to make them identical
- -u it avoids displaying redundant information
Example of input: diff text1.txt test2.txt
Compare two sorted files line by line and write to standard output.
Example of input: comm text1.txt test2.txt
Used to change your user password.
Example of input: passwd
Calculates the disk usage of a file or a directory.
- –h display human-readable form
- -s summarize the output total size
- -a lists the sizes of all files and directories in the given file path
- -c adds a line to the bottom of the output that gives you a grand total of all of the disk usage for the file path given
Example of input: du –hs /home
Reboot the system immediately.
Example of input: reboot
Provides the ability to launch and use multiple shell sessions from a single ssh session.
- –A it force all capabilities into each window’s termcap
- -S creates a named session
Example of input: screen -a
Shuts down the system, but make sure to close all of your files to avoid data loss.
Example of input: halt
The ps command lists the currently running process.
Example of input: ps aux
Kill a process.
Example of input: pkill processName
You can edit file, if it doesn't exist command will create new one
Example of input: nano
Example of input: dpkg -s libgtk-3-0|grep '^Version'
Runs command as superuser
Example of input: sudo touch
Provides with information about all running processes
Example of input: top
Shows memory usage
Example of input: free -h
Shows the hierarchy of files and folders in directory
- -f prints the full path prefix for each file
- -i ignores case when sorting filenames
Example of input: tree
Shows the ping of the website
- -c amount display ping amount time
Example of input: ping www.google.com
Show all open connections on your pс
- -D allows you to see packets coming into and going out of each layer in the communications subsystem along with packets dropped at each layer
Example of input: netstat
Shows ip and etc of your pc
Example of input: ifconfig
Shows all users on your machine
Example of input: w
Finds out the number of newline count, word count, byte and character count in the files specified by the File arguments
- -l prints the number of lines in a file
- -w prints the number of words in a file
- -c displays the count of bytes in a file
- -m prints the count of characters from a file
- -L prints only the length of the longest line in a file
Example of input: wc -L
Writes a random permutation of the input lines to standard output.
- -n prints the number of lines in a file
Example of input: shuf -n 25 hello.txt
Allows you to check if two files are identical.
- -b prints differing bytes
Example of input: cmp hello.txt test.txt