0% found this document useful (0 votes)
11 views

Commands

The document provides commands and descriptions for Linux terminal commands. Some key commands are pwd for showing the current directory, ls for listing files, cd for changing directories, and cat, head, tail for viewing file contents. It also covers commands for manipulating files and directories like cp, mv, mkdir, and rm. System information commands include ps, uptime, and commands for managing users and groups include useradd, usermod.

Uploaded by

Salma Soliman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Commands

The document provides commands and descriptions for Linux terminal commands. Some key commands are pwd for showing the current directory, ls for listing files, cd for changing directories, and cat, head, tail for viewing file contents. It also covers commands for manipulating files and directories like cp, mv, mkdir, and rm. System information commands include ps, uptime, and commands for managing users and groups include useradd, usermod.

Uploaded by

Salma Soliman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Commands

1. pwd:
I. pwd: Displays current path
2. date:
I. date: Displays current date
II. date +%A: Displays current DAY
III. date +%B: Displays current MONTH
IV. date +%C: Displays short date {11/28/21}
3. cal:
I. cal: displays current month calendar
II. cal [year]: Displays calendar for a specified year
III. cal [month] [year]: Displays calendar for specified month
4. clear:
I. clear: Clears the terminal
5. cd:
I. cd [target path]: changes working directory to target path
II. cd ~ : changes working directory to home directory
III. cd .. : changes working directory to parent directory
IV. cd ../.. : changes working directory to grandparent directory
6. whoami:
I. Prints the name of the current working user
7. ls:
I. ls: lists all files and directories in current path
II. ls -l: lists all files and directories as a long list (giving info about
files/dirs.)
III. ls -r: list everything in reverse order
IV. ls -a: lists everything including hidden files
V. ls [path]: list everything inside a given path
VI. ls -lh: list everything as human readable long list
VII. ls -t: lists everything sorted by timestamp
VIII. ls -R: list everything in current directory and everything in its children
directories
IX. ls ???: list files/directories that contains 3 characters, each {?}
represents a character
X. ls a*: list files/directories starting with {a}
XI. ls *a: list files/directories containing {a}
XII. ls -i: display “inode number” of files
XIII. ls [abc...]: list files/directories containing {a}, {b} or {c}
XIV. ls [!abc...]: list files/directories containing anything except {a}, {b} or
{c}
XV. ls [[:alpha:]]: list files/directories containing any alphabetic character
XVI. ls [[:lower:]]: list files/directories containing any lowercase character
XVII. ls [[:upper:]]: list files/directories containing any uppercase character
XVIII. ls [[:alnum:]]: list files/directories containing any alphabetic character
or a digit
XIX. ls [[:punct:]]: list files/directories containing any printable character
not a space or alphanumeric
XX. ls [[:digit:]]: list files/directories containing any alphabetic character
XXI. ls [[:space:]]: list files/directories containing any single white space
character. This may include tabs, newlines, carriage returns, form
feeds, or spaces
8. tty:
I. tty: stands for tele type which prints terminal file name
9. chvt:
I. chvt: stands for change virtual terminal, navigate to the target
terminal
10.exit:
I. exit: exits the current terminal

11. passwd:
I. passwd: changes the user password
12. file:
I. file [path]: prints the type of a specified file
13. which:
I. which[command]: prints th prints the path of user bash e location
where this command stores its files
II. which bash: prints the path of user bash
14. cat:
I. cat [file path]: prints the text inside the specified file
II. cat /etc/passwd: prints all the users in the system – like:
username:password:userid:primarygroupid:alias:user directory: user
default shell directory
III. cat /etc/shadow: prints all the passwords of the users but encrypted
IV. cat /etc/group: prints all existing groups – like: groupname:user
password:group id:included users in the group
15. head:
I. head [file path]: prints the first 10 lines of the target file
II. head -n 5 [file path]: prints the first 5 lines of the target file
III. head -n [num] [file path]: prints the first [num] lines of the target file
16. tail:
I. tail [file path]: prints the last 10 lines of the target file
II. tail -n 5 [file path]: prints the last 5 lines of the target file
III. tail -n [num] [file path]: prints the last [num] lines of the target file
17. wc:
I. wc [file path]: prints the number of lines, words, characters inside the
target file
II. wc [file path] -w: prints the number of words inside the target file
III. wc [file path] -l: prints the number of lines inside the target file
IV. wc [file path] -r: prints the number of characters inside the target file
18. history:
I. history: prints all the previously typed commands on this shell, stores
all this commands in file called {.bash_history}
II. history -c: clears history
III. ! 5: executes command number 5 in history
IV. ! [num]: executes command number [num] in history
V. !!: executes the last command in history
19. touch:
I. touch [file]: creates new file called {file} in current directory
II. touch [file2] [file 3]: creates new files called {file2} and {file3} in
current directory
III. touch [fileName] [extension]: creates new file with specified
extension or modify timestamp of existing file
20. mv:
I. [filename] [filepath]: move the target file to the target path
II. [filepath] [.]: move the target file to current directory
III. [filename1] [filename2]: rename filename1 to be named as
filename2
IV. mv [file1.txt] [targetPath/file2.txt]: move file1 to the target path and
rename it to be file2
21. cp:
I. cp [filepath] [destinationpath]: copy the target file to the target path
II. cp -r [source directory path] [target directory path]: copy source
folder to destination path
22. mkdir:
I. mkdir [directoryName]: make new folder [directoryName] inside the
current directory
II. mkdir [targetPath/dir2]: makes new directory {dir2} inside tagetPath
directory
23. rmdir:
I. rmdir [directoryName]: deletes specified directory from current
directory BUT the specified directory must be empty first.
24.rm:
I. rm [filename]: deletes specified file from current directory
II. rm -R [directoryName]: deletes specified directory from current
directory – used when specified directory is not empty
25. dir:
I. dir: list all the content of current directory
II. dir –color: list all the content of current directory and coloring files
and directories with different colors
26. date
I. date: print the current date and time
27. echo:
I. echo [message]: prints the given message on screen
II. echo Day_{Sunday,Monday,Tuesday,Wednesday}.log: prints
Day_Sunday.log, Day_Monday.log, etc
III. echo StudentID_{1..200}.txt: prints StudentID_1.txt,
StudentID_2.txt,…,StudentID_200.txt
IV. echo file{a,b,c}{1,2,3}.txt: prints filea1.txt filea2.txt filea3.txt fileb1.txt
fileb2.txt fileb3.txt filec1.txt filec2.txt filec3.txt
V. file{a{1,2},b,c}.txt: print filea1.txt filea2.txt fileb.txt filec.txt

28. > :
I. [command] > [file]: prints the output to the specified file by
overwriting its content using the given command
II. example:
i. echo [message] > [file]: deletes content of file then writes the
given message in the file
29. >> :
I. [command] >> [file]: prints the output to the specified file by
appending to its content using the given command
II. Example:
i. echo [message] >> [file]: writes the given messages in the file
without deleting any of its content
30. find:
I. find [target path] -name [file name]: search for the specified file
name in the target path
31. less:
I. less [filename]: prints the content of file page by page -- navigate
through pages using space -- quit from command using 'q'
32. more:
I. More [filename]: prints the content of the file by a percentage
33.|:
I. cat file1.txt | less
II. ls -lR | less
34. ln:
I. ln [pathOfExistingFile] [pathToNewHardlink]: create a hard link
between existing file and new file
II. ln -s [pathOfExistingFile] [pathToNewHardlink]: create a
soft/symbolic link between existing file and new file
35. Variable Expansion / Assigning and Using Variables:
I. Var = abcde:
II. Example:
i. Echo $Var: prints {abcde} – MUST put {$} before the variable
name
36. Command Substitution:
I. command is enclosed in parentheses, and preceded by a dollar sign
($)
II. Example:
i. echo Today is $(date +%A): prints Today is Sunday -- current
day ya3ne.
ii. echo Today is $(date): prints Today is Sun Jan 3 07:01:35 UTC
2021 – current date
37. Protecting Arguments from Expansion:
I. Use backslach “ \ ” to protect next character from expansion
II. Example:
i. echo The value of $HOME is your home directory.: prints The
value of /root is your home directory.
ii. echo The value of \$HOME is your home directory.: prints: The
value of $HOME is your home directory
38. ps aux:
I. ps aux: prints all the system processes
39. useradd :
I. useradd [username]: creates new user with the specified username
II. useradd [username] -c [alias] -s [default shell path]: creates new user
and set his alias & default user shell
III. useradd [username] -p [user password] -u [user id]: creates new user
and set his password and user id
IV. useradd [username] -e [date]: creates new user and set its expiration
date
40. usermod:
I. usermod [username] -c [alias] -s [default shell path]: modifies the
alias and default shell of existing user
II. usermod [username] -s [shell path]: like -- usermod ahmed -s
/usr/sbin/nologin -- makes the user has no shell and also has no login
access
III. usermod [username] -G [group name]: add the specified user to the
specified group as a secondary group for this user by overriding
IV. usermod [username] -aG [group name]: add the specified user to the
specified group as a secondary group for this user by appending
V. usermod -L [username]: lock the specified user
VI. usermod -U [username]: unlock the specified user
41. userdel:
I. userdel [username]: delete the specified user without user default
directory
II. userdel -r [username]: delete the specified user and the user default
directory
42. id:
I. id: displays current user info
II. id [username]: displays the info of the specified username
III. id -u [username]: displays only the user id of the specified username
43. passwd:
I. passwd [username]: change password for a specified user
44. groupadd:
I. groupadd [group name]: creates new group
45. groupmod:
I. groupmod [group name] -g [group id]: modifies the group id
II. groupmod -n [new name] [old name]: modifies group name
46.groupdel:
I. groupdel [group name]: delete the specified group
47. su:
I. su [username]: switch to this username
II. su - [username]: switch to this username and go to its default home
directory
48. sudo
I. FORCE ANY COMMAND AS IF YOU ARE ROOT
II. sudo passwd [username]: change password of another user
III. sudo apt update: update all the indices of apt repositories
49. vim:
I. vim /etc/sudoers: this file contains the privilages of the users
50. exit:
I. exit: logout and switch to the previous user

You might also like