Linux Basics

I would like to give a brief intro for all the basic commands which will be required for all the new comers in Linux., I will continue this article with more commands in another page.

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

googletag.pubads().definePassback('/63833091/21738297400', [480, 320]).display();


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

googletag.pubads().definePassback('/63833091/21738297400', [480, 320]).display();

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

googletag.pubads().definePassback('/63833091/21738297400', [480, 320]).display();

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

close button