Wednesday, July 2, 2014

A-Z bash commands

A
 
alias: If creating an alias is what you want, then this is it.
apropos: We’re not the only ones providing help. This command you to search through the Help manual pages.
apt-get: This one works on Debian and Ubuntu distros. It is used to install and search for software packages.
aptitude: See the similarity with the above command? This one does the same thing.
aspell: Got bad spellings? Use the spell checker.
awk:No, this command is not for awkward situations. It lets you find text and replace it. Also, you can sort, index and validate things in a database. 

B
 
basename: Sometimes files and directories have suffixes to their names. This one strips them off it.
bash: GNU Bourne-Again Shell
bc: This command is an arbitrary precision calculator language
bg: bg could stand for background couldn’t it? Regardless, that’s what it does, sends to the background
break: Exit from a loop
builtin: Run a shell builtin
bzip2: When there’s ‘zip’ in the name, that’s what it does. It compresses or decompresses files that are named. 

C
cal: Need a calendar? This command displays one.
case: In ‘case’ you want to perform a command conditionally. This is how to do it.
cat: In programming, ‘cat’ usually stands for concatenate. Here too, but this command displays the content of the files after concatenation.
cd: Change Directory
cfdisk: In Linux, this command is the partition table manipulator
chgrp: This is how you change the ownership of a group.
chmod:‘Ch’ is for change. This one changes the access permissions.
chown: This one sounds too much like clown! Anyway, it’s not funny though. It changes the owner and group of a file.
chroot: Using this you can run a command, but with a different root directory
chkconfig System services (runlevel)
cksum: It displays the CRC checksum ad byte counts.
clear: If you need to clear the terminal screen, use this command.
cmp: Compare two files
comm: Compare two sorted files line by line
command: Run a command - ignoring shell functions
continue: This is for resuming the next iteration of a particular loop.
cp: Make a copy of files to a different location.
cron: Daemon to execute scheduled commands
crontab: Scheduling is sometimes very important. This command does it, it schedules a command that will run at a specified time.
csplit: Split a file into context-determined pieces
cut: When you need to cut down a file into parts, this is the command to use. 

D

date: Use this command to change the date and time.
dc: The command stands for Desk Calculator.
ddrescue: Like most other such commands, this is the disk recovery tool.
declare: This command is used to declare the variables and to give attributes.
df: When you want to know the free space on your disk, use this.
diff: This command prints the differences between two files.
diff3: This is the same command as the previous one, but for three files.
dig: Need to lookup the DNS? Use this.
dir: Use this command for listing directory contents briefly.
dircolors: This command is used for colour setup for the ‘ls’ command.
dirname: Use this command to change a full pathname into just a path.
dirs: This command shows you the list of directories that are remembered.
dmesg: Use this command when you want to print kernel and driver messages.
du: Use this command to get an estimation of the file space usage. 

E

echo: This command is used for displaying message on the screen.
egrep: This searches for files that have lines matching an extended expression.
eject: Use this when you need to eject a removable media.
enable: Use this to disable or enable bulletin shell commands.
env: Environment variables
ethtool: Ethernet card settings
eval: This command is used when you need to evaluate a many commands.
exec: For executing a command.
exit: Exiting the shell.
expand: This command converts all the tabs to spaces.
export: This command sets an environment variable.
expr: Some evaluate commands, this evaluates expressions. 

F

false: Do nothing, unsuccessfully
fdformat: This command is used for low level format of a floppy disk.
fdisk: This is a partition table manipulator for Linux systems.
fg: This command is used for sending a task to the foreground.
fgrep: Use this command to search through files for tasks that match a string.
file: This is used to determine the file type.
find: This is used to find files that match a desired criteria.
fmt: This is used for reformatting paragraph text.
fold: The name is quite suggestive, it wraps text in order to fit a certain width.
format: This simply formats tapes or disks.
free: Use this to see the memory usage.
fsck: This is used for checking the consistency of the file system and repair it.
fuser: This command identifies and kills the process accessing a file. 

G

gawk: This command is used to find text within files and replace it.
getopts: Parse positional parameters
grep: Through this you can search in files for lines matching a certain pattern.
groupadd: Use this command to add security user groups.
groupdel: This one is used for deleting a certain group.
groupmod: While the last one deletes, this one modified a group.
groups: Print the names of groups in which an user is located.
gzip: This command is used for compressing and decompressing files. 

H

hash: This command is used to refer to the complete pathname of a name argument.
head: Use this for output for the first part of files.
help: Display the built in help for a command.
history: Command History
hostname: Print or set system name 

I

iconv: Use this to convert the character set in files.
id: Display the group ids or user ids.
if: Conditional command.
ifconfig: Used to configure network interfaces.
ifdown: Use this command for stopping a network interface.
ifup: Start a network interface app with this command.
import: Used for the X server. Capture a screen and save image.
Install: Set attributes and copy files 

J

jobs: Use this for listing jobs that are active.
Join: This one joins lines, which are on a common field. 

K

kill: Stops a process from running.
Killall: Kills the processes by name. 

L

less: This command displays the output on a single screen at a time.
let: This is for doing arithmetic on shell variables.
link: This command is used for creating a link to another file.
ln: This one creates a symbolic link to another file.
local: Use this for creating variables.
locate: This one is used for finding files.
logname: This is used to print the login name being used currently.
logout: Use this command to exit a login shell.
look: When you just want to see lines that start with a particular string.
lpc: It stands for Line Printer Control.
lpr: This is for offline print.
lprint: Use this command to print a file.
lprintd: Use this to abort an ongoing print job.
lprintq: This command lists the print queue.
lprm: This removes the jobs from the print queue. 

M

make: This command is used for recompiling the group of programs.
man: This is short for manual and provides help on a command.
mkdir: Creating directories.
mkfifo: Use this to make FIFOs.
mknod: This is to create character special files or block files.
more: This displays the output, but in a single screen at a time.
mount: Used for mounting a particular filesystem.
mtools: Manipulating files from MS-DOS.
mtr: Network diagnostics command for things like ping and traceroute.
mv: Used for moving and renaming files and directories.
mmv: Mass Move and Rename 

N

netstat: Get information on networking.
nice: Use this to set the priority of a job or a command.
nl: Write files and number lines.
nohup: This one runs a command, which is not affected by hangups.
notify-send: This command sends desktop notifications.
nslookup: This command is used to query internet name servers interactively. 

O

open: This command opens a file in its default application.
op: Use this command for gaining operator access. 

L

less: This command displays the output on a single screen at a time.
let: This is for doing arithmetic on shell variables.
link: This command is used for creating a link to another file.
ln: This one creates a symbolic link to another file.
local: Use this for creating variables.
locate: This one is used for finding files.
logname: This is used to print the login name being used currently.
logout: Use this command to exit a login shell.
look: When you just want to see lines that start with a particular string.
lpc: It stands for Line Printer Control.
lpr: This is for offline print.
lprint: Use this command to print a file.
lprintd: Use this to abort an ongoing print job.
lprintq: This command lists the print queue.
lprm: This removes the jobs from the print queue. 

M

make: This command is used for recompiling the group of programs.
man: This is short for manual and provides help on a command.
mkdir: Creating directories.
mkfifo: Use this to make FIFOs.
mknod: This is to create character special files or block files.
more: This displays the output, but in a single screen at a time.
mount: Used for mounting a particular filesystem.
mtools: Manipulating files from MS-DOS.
mtr: Network diagnostics command for things like ping and traceroute.
mv: Used for moving and renaming files and directories.
mmv: Mass Move and Rename 

N

netstat: Get information on networking.
nice: Use this to set the priority of a job or a command.
nl: Write files and number lines.
nohup: This one runs a command, which is not affected by hangups.
notify-send: This command sends desktop notifications.
nslookup: This command is used to query internet name servers interactively. 

O

open: This command opens a file in its default application.
op: Use this command for gaining operator access. 

P

passwd: Use this command to modify user passwords.
paste: This command is used for merging lines in files.
pathchk: It is used to check the portability of a file name.
ping: This command is used for testing network connections.
pkill: This command stops processes from running.
popd: This command restores the previous value of the directory you’re currently in.
pr: Prepare your files for printing using this.
printcap: Printer capability database
printenv: Print environment variables
printf: This command is used for formatting and printing data.
ps: This stands for Process Status.
pushd: Change the directory and save it first.
pwd: It stands for Print Working Directory. 

Q

quota: This command displays the disk usage and its limits.
quotacheck: This commands lets you scan a file system to find its disk usage.
quotactl: This is used to set disk quotas. 

R

ram: Ram disk device
rcp: When using two machines, this command copies files between them.
read: This commands is used for reading a line from standard input.
readarray: This commands reads from stdin into an array variable.
readonly: This command marks the variables and functions as readonly.
reboot: Self explanatory, use this command to reboot your system.
rename: Rename files
renice: This command alters the priority of the processes running.
remsync: This command synchronises remote files through email.
return: This is used to exit from a shell function.
rev: This command reverses the lines in a file.
rm: Use this to remove particular files.
rmdir: Same as above, but for directories.
rsync: This is for synchronising file trees. 

S

screen: Use this to run remote shells using ssh.
scp: This is used to create a secure copy.
sdiff: This command is used to merge two files in a secure manner.
sed: This is for the stream editor.
select: This is used when you need to accept keyboard inputs.
seq: This command is used for printing numeric sequences.
set: This command lets you manipulate shell functions and variables.
sftp: Run the secure file transfer program using this.
shift: This command is used for shifting positional parameters.
shopt: Shopt stands for Shell Options.
shutdown: Use this command when you want to shutdown Linux or restart it.
sleep: Add a delay using this command.
slocate: This is used to find particular files.
sort: Text files are sorted using this.
source: This command is used for running commands from a file.
split: This command is used to break a file into fixed sizes.
ssh: This is used to run the remote login program, that is, the secure shell client.
strace: This is used to trace signals and system calls.
su: Substitute the user identity using this command.
sudo: This is used for executing commands as a different user.
sum: File cheksums are printed using this command.
suspend: This command is used to suspend the execution of the current shell.
sync: This command is used in order to synchronise data from a disk with the memory. 

T
tail: Use this command when you want to output only the last part of a file.
tar: This command is used in order to store a list or extract files in an archive.
tee: This command is used for redirecting output into multiple files.
test: This command is used for evaluating conditional expressions.
time: The running time of a program can be measured using this command.
timeout: This command is used to put a time limit on a command.
times: Use this to find the user and system times.
touch: Timestamps on a file can be changed using this.
top: This is used to get a list of the processes that are running on the system.
traceroute: Use this command to Trace Route to a host.
tr: Delete characters, translate or squeeze them.
tsort: This is used for topological sorting.
tty: This is used for printing the filename of terminal on stdin. 

U

ulimit: This commands limits the user resources.
umask: This is used to determine the file permission for a new file.
umount: This command will unmount a device from the system.
unalias: This command will remove an alias.
uname: This command will print the system information.
unexpand: This command will convert the spaces in a file to tabs.
uniq: This command will uniquify your files.
units: This will convert the units from one scale to another.
unset: This command removes the variable names or the function names.
unshar: This command unpacks the shell archive scripts.
until: This command will execute a command until there is an error.
uptime: This command will show the uptime.
useradd: Use this command when you need a new user account to be created.
userdel: This command will delete an user account from your system.
usermod: Self explanatory, modify an user account.
users: This command gives you a list of users who are currently logged in.
uuencode: This command will encode binary files. 

V

v: This command lists the contents of a directory.
vdir: Same as above.
vi: This is a text editor.
vmstat: This command will report on the virtual memory statistics. 

W

wait: This command directs the system to wait for a process to finish.
watch: This command will display or execute a program periodically.
wc: This command prints the word, byte and line counts.
whereis: This command will search a user’s $path, source files and man pages
which: This command searches only for a user’s $path for a program.
while: Use this to execute commands.
who: This command will print the usernames that are currently logged into the system.
whoami: This is a command that prints the current name and user id.
wget: This will retrieve the web pages or files through HTTP, HTTPS or FTP.
write: Use this to send messages to other users. 

X

xargs: This command execute’s a utility and passes a constructed argument list.
xdg-open: This lets you open an URL or a file in the user's preferred application. 

Y
yes: This command will print a string until it is interrupted.

Tuesday, July 1, 2014

Useful Linux Commands

Useful Linux Commands

df # disk space

free -g # memory info in Megabytes

uname -a # shows tech info about machine

bc # command-line calculator (to exit type 'quit')

wget ftp://ftp.ncbi.nih.... # file download from web

/sbin/ifconfig # give IP and other network info

ln -s original_filename new_filename # creates symbolic link to file or directory

du -sh # displays disk space usage of current directory

du -sh * # displays disk space usage of individual files/directories

du -s * | sort -nr # shows disk space used by different directories/files sorted by size

shortcuts

Handy shortcuts
Anywhere in Command Line:
up(down)_key - scrolls through command history
history # shows all commands you have used recently

Auto Completion:
<something-incomplete> TAB - completes program_path/file_name
Taking control over the cursor (the pointer on the command line):
Ctrl+a # cursor to beginning of command line
Ctrl+e # cursor to end of command line
Ctrl-w # Cut last word
Ctrl+k # cut to the end of the line
Ctrl+y # paste content that was cut earlier (by Ctrl-w or Ctrl-k)

When specifying file names:
"." (dot) - refers to the present working directory
"~" (Tilda) or "~/" - refers to user's home directory
Unix Help
man <something> # general help (press the 'q' key to exit)
man wc # manual on program 'word count' wc
wc --help # short help on wc

soap -h # for less standard programs
Online help: Google
Universally available Linux commands, with detailed examples and explanations: http://www.linuxconfig.org/linux-commands

Finding Things
Finding files, directories and applications
find -name "*pattern*" # searches for *pattern* in and below current directory
find /usr/local -name "*blast*" # finds file names *blast* in specfied directory
find /usr/local -iname "*blast*" # same as above, but case insensitive
additional useful arguments: -user <user name>, -group <group name>, -ctime <number of days ago changed>
find ~ -type f -mtime -2 # finds all files you have modified in the last two days
locate <pattern> # finds files and dirs that are written into update file
which <application_name> # location of application
whereis <application_name> # searches for executeables in set of directories
dpkg -l | grep mypattern # find Debian packages and refine search with grep pattern

Finding things in files
grep pattern file # provides lines in 'file' where pattern 'appears',
# if pattern is shell function use single-quotes: '>'


grep -H pattern # -H prints out file name in front of pattern
grep 'pattern' file | wc # pipes lines with pattern into word count wc
# wc arguments: -c: show only bytes, -w: show only words,
# -l: show only lines; help on regular expressions:
# $ man 7 regex or man perlre


find /home/my_dir -name '*.txt' | xargs grep -c ^.* # counts line numbers on many
# files and records each count along with individual file
# name; find and xargs are used to circumvent the Linux
# wildcard limit to apply this function on thousands of files.

Friday, June 27, 2014

Basic commands

The Commands which are basically use to operate an Operating System(O/S) is called Basic Commands.  

1) pwd :  present working directory ---> used to know the path of present user.

2) ls : list ------>It gives the list of files & Directories present in the path


3) ls -l or ll --------> Listing of all files along with attributes


4) ls -a ------> Lists all hidden files & directories


5) ls -r -------> lists all files & directories in reverse mode


6) ls -il---------> lists all files & directories along with inode numbers


7) ls -ld < directory name> ------> to view attributes of a particular directory


8) ls -R <directory.name> -------> to view tree structure of a directory


9) ls -a* ----------> to view all files & directories starts with a


10) man < command> ---------> to view entire options of a command


To create a file we have 3 methods :

1) touch

2) cat

3) vi(vim)

1) touch : With the help of touch command we can create an empty file.
    
      syntax: touch < filename>
        
             ex: touch f1

   with this command we can create n number of files at a time.
       
           syntax: touch  <file1> <file2> <file3>
           ex: touch mahesh raju naveen

2)cat:  By using cat we can create data-files
   
     syntax: cat > <filename>
         ex: cat  >mahesh
             
              (edit data)
             ( ctrl+d)(to save)

 To view content of a file

    
           cat < filename>

To add data in existing file


           cat >> <existing filename>
       
            (enter-data)
            (ctrl+d)

we cannot edit the written text through cat command. we can only add data to modify existing data we have to use editors. we have number of editors in linux

      
             ex: gedit ,nano, kedit, kate, emacs ,vim ,etc...
  
   Note : but we always use the best editor "vim" editor .

we can transfer an output as input for another file
        
           ex: to view output of file1 file2 we use 

                    cat file1 file2
 In the same way, we can transfer output of that command as input for another file 
    
           ex: cat file1 file2 > file3
here we are giving file1 file2's data as input for file3 , by this data of file1&file2 will copied into file3.

Linux Basic Commands

Linux Basic Commands 



                   Command
Description
1. logname
Current user name
2. pwd
Present working directory
3. uname
Display kernel name
4. uname -n
Print network hostname
5. uname -r
Display kernel version
6. uname -v
Display kernel release date
7. uname -i
Print hardware platform
8. uname -o
Print the operating system
9. uname -p
Print the processser name
10. uname -a
Print all information
11. date
Display system date and time
12. clear
To clear the screen
13. cal
Display current month calendar
14. cal 2014
Display 2014 calendar
15. cal 9 1987
Displays the September 1987 calendar
16. bc
Open calculator
17. bc -v
Version of calculator
18. hostname
Display server name
19. hostname -i
Display server IP address
20. tty
Display terminal name
21. who
To display how many users connected to server
22. whoami
Display current username
23. uptime
Display how long server is “up &running”, no. Of users connected &avg load on the server.
24. which <command name>
Show the full path of command
25. whereis  <command name>
Display the binary, source, and manual page files for a command
26. find
Search for files in a directory hierarchy
 
       27.   set system date and time
            # date -s “yyyy-mm-dd hh:mm:ss”
      28.   To view help for a command (manual pages)
 
           # man <command>
 29. Viewing list of Files & Directories:
          Syntax : # ls  <options>   <file>
                   Options:     
                                    -a    --> To check the hidden object


                                    -l    --> To list the properties of an object

           

                                    -s    --> To check the size in block


                                    -r    --> To check reverse order


                        -R   --> List Sub directories Recursively


                                    -Q   --> To see files in double quotes


                                    -m   --> List of entries with comma separated

                   Eg :- 
                                                # ls -a


                                                # ls -la


                                                # ls -lr
Working with Files:-
   
                      A collection of data is called file. In linux – platform, CAT, Touch, vi are some at the default commands. To create a file, but there are some differences between these three commands.

30. Cat (concatenation):
                     This command is used to create single file with data and also to check the data of exiting file, but we cannot modify the data.
Create a file :
                        # cat > file


                           -------------


                           -------------


                        ctrl+d (save & quit)
31. Open the file:
                # cat < filename


                             or


               # cat filename
32. To append the file:
                 # cat >> filename


                        ---------------------

           

                        --------------------


                     ctrl+d (save & quit)
33. To open multiple files:
               # cat file1 file2 file3

 Disadvantages:
               Using this command we can't create multiple files and we can't edit the text at the file.
 Touch:
                This command is used to create multiple files, but are empty files and also it use to change date and time of an existing files and directories.
34. To create multiple files:
             # touch  f1 f2 f3
Disadvantages:
                Using  this command we can't modify the text of the database files.
       35.   change current Date and Time: 
             
                               # touch f1
       36.  Change Time stamp of a file or directory
Syntax
 
              # touch <option> <argument>  <file/directory>


              # touch –t  YYYYMMDDHHMM  <file/directory-name>

Deleting the files :
  37.          “rm” command is used for remove files
 38.           # rm <filename>
 39.          # rm -i <filename>   -->  asking confirmation
 40.          # rm -f <filename>   -->  delete file forcibility.
 41.        Remove multiple files at once
           # rm <file 1> <file 2> <file 3>
Working with Directories:
        “mkdir” (Make Directory) command is used for creating Directories.
      Syntex:   # mkdir  <option>  <Directory name>
  
  42.         To create a Directory
                            # mkdir <dir name>
  43                   Creating multiple directories
                                    # mkdir dir1 dir2 dir3
  
 44.                Creating nested tree structure (sub directories inside directories)
                                    # mkdir -p world/asia/india/ap/hyd/kphb
45.              To check nested directories
                                    # ls -R world  
                                        (or)
                                 # tree world
Removing Directories:
46.                           “rmdir” (remove directory) command is used to delete an empty directory.
                                 # rmdir <dirname>
47.             “rm -r” command is used to delete recursively entire directory.
                                # rm -r <dirname>
48.                           # rm -ri <dirname>   --> asking confirmation message
49.                           # rm -rf   <dirname>   --> remove forcefully.
Navigation Commands:
  50.                      # cd         --> To change a directory
  51.                     # cd  ..   --> To move one level back
  52.                    # cd ../.. -->  To move two levels back
  53.                    # cd -          --> To go to the previous working directory
   54.                   # cd   <space-bar>    --> To go to the users home directory
   55.                   # cd <dir-name>       -->  To move to the particular directory.
Copying files and directories :

            “cp” command is used to copy file or directory from one place to another.

 56.                                           To copy a file
                                    # cp file1 file2  
57.                                        To copy a file into directory
                                    # cp file1  dir1
58.                                   To copy multiple files into a directory
                                    # cp file1 file2 file3  dir1
59.                                       To copy a directory
                                    # cp -R <source directory>  <destination dir>
                                    # cp -R dir1  dir2
Move and Rename – Files and Directories :
                        “mv” (move) command is used to move files and directories from one place to another, and also this command is used to rename the file and directories.
            Syntex:   # mv <option>  <source>  <destination>
  
60.                                                 To move a file
                                    # mv file1 dir1
61.                                               To move a directory
                                    # mv dir1 dir2
62.                                                 Renaming file and directory
                                    # mv  <old name>  <new name>
Creating hidden files and directories :
  To hide a file start file name with “.” character
   63.                       # cat  > .filename
   64.                      # mv  file1  .file1  (To hide existing file)
   65.                      # mv  .file1  file1  (To unhide a file)
   66.                      # mkdir  .dir1   (To create hidden directory)
   67.                     # mv .dir1 dir1    (To unhide a directory)
                                   
 68.          # ls  -l (or ll )     (Display longlist format, i.e, with 9 fields)
(i) File type,  where '-' is a file  and  'd' is a directory.
(ii) permissions of file or directory
(iii) Number of links  (l)  --> link file
(iv) owner  of the file
(v) Group of file
(vi) File size in bytes
(vii) Creation data of file
(viii) Creation time of file
(ix) Name of file
 Identify Files & Directories with colors:
         
                        # ls  -l
                                     Files          -     Black
                                    Directories  -    Blue
                                    Links           -     Skyblue
                                    Zip              -     Red