Bioinformatics Tools

Pages

Wednesday, January 29, 2014

LINUX BASICS FOR BEGINNERS AND ADVANCE USERS

Since long I was trying to learn Linux. I realized it is not as difficult as it seems. I have compiled some of the basic commands that are mandatory to learn to step into this beautiful world. They are not all, I have skipped grep, awk and sed knowingly, as I presume they deserve bit more attention. I will keep updating the list as soon as I can. Do look around too, some good video tutorials are also available that aid in learning. Also, I have made this available as a simple printable PDF. 

LINUX BASICS FOR ADVANCE USERS       - Download Here

Basic commands: On the terminal type these commands at-least two-three times to practice. Also, it is advisable to read man (help) pages of all these commands at least once.

####################################################

Command

Function
man <command>
:
Displays manual or help page for a commend, always read it full at least once
cd
:
Change directory, to navigate from one directory to another
cd -
:
Toggle between previous directory and current directory
ls
:
List files or folders, with several arguments give detail information about the files and folders, try: ls -ltrh
date
:
Displays current date
ssh
:
login to remote host
passwd
:
Change password
bc
:
Opens calculator
cp
:
Copies files or directories, usage: cp file.txt /directory
mv
:
Moves file, rename file, usage: mv file1.txt file2.txt (renames file1.txt to file2.txt)
pwd
:
Present working directory
mkdir
:
Make a new directory, usage: mkdir dir1 ; creates directory dir1
rmdir
:
Removes empty directory
cal
:
Opens calendar
echo
:
Displays message, usage: echo "hi" ; displays hi
printf
:
Alternative to echo, displays message
script
:
Records your session
uname
:
Know about your machine, usage: uname -a
tty
:
Know your terminal
stty
:
Display and setting terminal characteristics
gzip
:
Compressing files
gunzip
:
Decompress files
tar
:
Archival program
head <filename>
:
Displays beginning of a file
tail <filename>
:
Displays end of a file
exit
:
Exits terminal
who
:
Who is logged into the system
whoami
:
Username
hostname
:
Machine name
rm -r
:
Removes directory including its content recursively (be careful)
ctrl+w
:
Cuts last work with keyboard while typing on terminal
ctrl+y
:
 Paste with keyboard
ctrl+a
:
Cursor at the beginning of the line while typing on terminal
ctrl+e
:
End of the line while typing on terminal
ctrl+k
:
Cuts to the end of the line while typing on terminal
ctra+c
:
Kills the process currently running
history
:
History of all the commands on terminal
~
:
Home directory, you ca do [ cd ~ ] to go to the home directory
wc
:
Word count, can be combined (piped through) various other commands (it gives results as lines, words and characters)
wc -c
:
Counts the number of bytes
wc -w
:
Counts the number of words
wc -l
:
Counts the number of lines
free -m
:
Free memory (ram) in mb
free -g
:
Free memory (ram) in gb
df
:
Disk space
du - sch <dir>
:
Disk space of the current directory
du -sch *
:
Disk space of individual files or directories
du -sch * | sort -nr
:
Disk space of individual files or directories sorted by file size
w
:
Who is logged onto the system and what are they doing
ps
:
Processes running by the users
ps -e
:
All the processes running in the system, also used with argument -a, -x, read man ps
ps -o %t -p <pid>
:
How long the process was running
ctrl+z
:
Suspend or sleep the current running process in foreground
bg
:
Run process in background
fg
:
Bring processes foreground, those running in background
kill <pid>
:
Kills a process with the given process id
kill -9 <pid>
:
Violently kills a given process id giving it no time to cleanup
kill -l <pid>
:
List all signals that can be sent to a process
kill -s sigstop <pid>
:
Suspends or sleep a process
kill -s sigcont <pid>
:
Resumes or wakes up a process
renice -n <value> <pid>
:
Gives a priority value to the process id, ranges from 1-19, higher the value lower the priority, default is 10, it is said to be how nice the process is i.e. How much ram it leaves for other process to run
cmp <file1> <file2>
:
Compares two given files
diff <file1> <file2>
:
Find the differences between two files, compares two files, argument -w ignores whitespace
mount
:
Mounts drive, usage: mount /media/usb
umount
:
Unmounts drive, usage: /media/usb
eject
:
Ejects cd rom, usage: /media/cdrom
join
:
Combines lines from two files on a common field, usage: join file1.txt file2.txt
tr a-z A-Z < file.txt
:
Transfers case to another i.e. Lowercase to uppercase
tr A-Z a-z < file.txt
:
Transfers case to another i.e. Uppercase to lowercase
xargs
:
Takes output of one command and passes it as an argument to another command usage: cat urllist.txt | xargs wget -c
sort
:
Sorts the lines of a text files in ascending order, usage: sort file.txt ; argument -r sorts in descending order, usage: sort -r file.txt ; argument -t is delimiter (colon, space, comma, tab etc.), usage: sort -t: file.txt ; argument -k sorts on a particular field, I recommend to read more on this, important and very helpful, used in combination with other commands [ man sort ]
uniq
:
Removes duplicate entries from sorted files, therefore mostly used in combination with sort, in order for uniq to work, all the duplicate entries should be in adjacent lines, usage: sort names.txt | uniq ; sort -u names.txt ; to count duplicate lines: sort file.txt | uniq -c ;  to display duplicate entries: sort file.txt | uniq -cd
cut
:
Used to display only specific columns from a text file or other command outputs i.e. To display first field from a colon delimited file : cut -d: -f 1 file.txt ; to display first and third field from colon delimited file : cut -d: -f 1, 3 file.txt
find
:
Find files, usage: find [pathname] [condition], arguments it takes are -name (for names of the files), -type (for type of file) -size (for size of file i.e. +100m, -mtime (modified time in days i.e. +60 or -2), -exec
stat
:
Used either to check the status or properties of single file or file system, usage: stat /etc/file.txt ; argument -f i.e. Stat -f / (displays the status of the file system i.e. Size/total/free/available
ac -d
:
Displays the statics about the user connect time, argument -d breaks the output for individual days, usage: ac -d username
&
:
At the end of the command executes job in the background but if you logout the job will be killed
nohup
:
At the beginning of the command executes job in background with (ampercent &), usage: nohup ./script.sh & ; the job will run in background even if you logout
screen
:
Once you logout the same session will not be connected, to do that, end with screen and attach it later by screen to get back as it was when you logged out
at
:
Schedule job i.e. At -f backup.sh 10am tomorrow
watch
:
To execute command continuously at certain intervals, usage: watch df -h
split
:
Splits the given file (big file) as per the requirement with respective arguments, i.e. File size, number of lines, etc.

No comments: