Basic Linux Commands
# tty Shows the current logged in terminal
# whoami shows the currently logged in user
# which "command name" reveals where in the search path a program is located
# echo prints to the screen
# echo $PATH dumps the current path to STDOUT
# echo $PWD dumps ths contents of the $PWD variable
# echo $OLDPWD dumps the most recently visited directory
# clear clears the screen or terminal
# reset resets the screen buffer
# history reveals your command history
# !110 executes the 110th command in our history
Files and Directories
# ls list the files and directories in the present working directories
# ls -ltr sort the files in the last modification time in reverse order
# ls -a list all the files including hidden files and directories ( all files starting with "." are hidden files)
# ls -l long list of all files and directories where you can check the relative permission on each file.
# mkdir "directory name" Create directory
# mkdir -p /"dir1"/"dir2"/"dir3"/ Create directory including parent dir
# touch "filename" Create files
# cp "dir1" /root/ copy directory or file to another location
# mv dir1 /root/ move or rename the dir or file to different location
# rm "dir name" To remove directory
# rm -rf "dir name" To remove a directory recursively and forcefully
For further switches to be used with any of the above commands you can check using
# man "command name"
# "command name" --help
For example:
# rm --help
# mkdir --help
# ls --help
# cd with no options changes to the $HOME directory
# cd ~ changes to the $HOME directory
# cd / changes to the root of the file system
# cd Desktop/ changes us to the relative directory 'Desktop'
# cd .. changes us one-level up in the directory tree
# cd ../.. changes us two-levels up in the directory tree
User and Group related
# useradd "username" creates a user
# passwd "username" Assign password to user
# groupadd "groupname" creates a group
# usermod -a -G "groupname" "username" Add existing user to group
# groupmod -A username groupname Add existing user to group
# useradd -d "directory name" -s "shell" -g "group name" -u "UID" "username" Creates user with provided details
Command chain
# head /var/log/messages displays opening lines of text files
# head -10 /var/log/messages displays opening 10 lines of text files
# tail /var/log/messages displays the closing lines of text files
# tail -10 /var/log/messages displays the closing 10 lines of text files
# wc -l /var/log/messages counts words and optionally lines of text files
No comments:
Post a Comment