linux shell commands code example

Example 1: linux commands

Linux Commands (Case Sensitive):

Basic:
pwd                ==> print the name of current directory   || Ex: pwd
whoami             ==> print the current user                || Ex: whoami
cd [directoryName] ==> enter a directory               		 || Ex: cd Music
cd ..              ==> go back to the parent directory       || Ex: cd ..
cp [file]          ==> copy file                             || Ex: cp music.mp3
ls                 ==> list all items in the current folder  || Ex: ls
clear              ==> clears the terminal                   || Ex: clear
mkdir [foldername] ==> makes folder with the specified name  || Ex: mkdir Songs
rmdir [foldername] ==> removes the specified folder          || Ex: rmdir Songs
echo "text"        ==> print the specified text			     || Ex: echo "Hi"

For sorting files:
mv [file] [newname]==> rename a file or folder  			 || Ex: mv exe txt
cat [filename]     ==> reads the specified file              || Ex: cat cmds.txt
tac [filename]     ==> reads the specified file in reverse   || Ex: tac cmds.txt
tail [file, file]  ==> reads first 10 lines of the files     || Ex: tail cmds.txt
zip [file, file]   ==> compresses the specified files        || Ex: zip files
vi [file]          ==> edit file in the terminal             || Ex: vi cmds.txt
gedit [file]       ==> edits the file in text editor         || Ex: gedit cm.txt
nano [file]        ==> edit file in nano editor              || Ex: nano cmds.txt
tar                ==> same as bzip2 						 || Ex: tar file
bzip2 -z / -d      ==> compress and decompress files with    || Ex: bzip2 -z cmds
                       the extension "bz2" respectively  
gzip               ==> same as bzip2 but compresses files    || Ex: gzip file
						with a gz extension.

More advanced: 
man [command]      ==> show the manual of the command        || Ex: ls man
reboot             ==> reboot the system                     || Ex: reboot
[command] --help   ==> similar to man but prints in terminal || Ex: pwd --help
users              ==> prints the current logged in user     || Ex: users
adduser            ==> adds another user                     || Ex: adduser David
deluser            ==> deletes a user                        || Ex: deluser David
ifconfig           ==> prints the details about your network || Ex: ifconfig
su [username]      ==> impersonate as the specified user     || Ex: su root
passwd             ==> change the password of current user   || Ex: passwd
exit               ==> exit the current user or the terminal || Ex: exit

Extras: 
users              ==> shows names of users logged in        || Ex: users
uptime             ==> shows how long the system has been    || Ex: uptime
                       running, number logged on users and 
                       the system load averages
uname -a          ==> show  all the information of the OS    || Ex: uname -a

Example 2: what are the shell commands

ls	ls       -   Lists files in current directory
ls -alF	     -   List in long format
cd	         - change directory
cd tempdir   - Change directory to tempdir
cd..         - Move back one directory
mkdir        - Make a directory
rmdir        - Remove directory(Must be empty)
cp           - Copy File into Directory
rm           - Remove or Delete File
rm *.tmp     - Remove all file
mv           - Move or rename files
more         - Look at file, one page at a time
lpr          - Send file to printer
man          - Online help about command
passwd       - Change password
gzip         - Compress file
grep<str><files> - Find which files contain certain word
who          - Lists who is logged on your machine
history      - Lists command history
date         - Print out current date
whoami       - returns your username
pwd          - tell where currently you are

Example 3: shell commands

compgen -c	#Check commands in Unix
help | more	#Check commands in Windows

Example 4: linux shell system commands

if `ls -la`.ok {
    echo("hello world")
}

Example 5: linux shell system commands

`sleep 10 &`
echo("This will be printed right away!")