linux tricks

24
1. Everything in Linux is a file including the hardware and even the directories. 2. # : Denotes the super(root) user 3. $ : Denotes the normal user 4. /root: Denotes the super user’s directory /home: Denotes the normal user’s directory. 5. Switching between Terminals § Ctrl + Alt + F1-F6: Console login § Ctrl + Alt + F7: GUI login 6. The Magic Tab: Instead of typing the whole filename if the unique pattern for a particular file is given then the remaining characters need not be typed and can be obtained automatically using the Tab button. 7. ~(Tilde): Denotes the current user’s home directory 8. Ctrl + Z: To stop a command that is working interactively without terminating it. 9. Ctrl + C: To stop a command that is not responding. (Cancellation). 10. Ctrl + D: To send the EOF( End of File) signal to a command normally when you see ‘>’. 11. Ctrl + W: To erase the text you have entered a word at a time. 12. Up arrow key: To redisplay the last executed command. The Down arrow key can be used to print the next command used after using the Up arrow key previously. 13. The history command can be cleared using a simple option –c (clear). 14. cd : The cd command can be used trickily in the following ways: cd : To switch to the home user cd * : To change directory to the first file in the directory (only if the first file is a directory) cd .. : To move back a folder cd - : To return to the last directory you were in 15. Files starting with a dot (.) are a hidden file. 16. To view hidden files: ls -a 17. ls: The ls command can be use trickily in the following ways: ls -lR : To view a long list of all the files (which includes directories) and their subdirectories recursively . ls *.* : To view a list of all the files with extensions only.

Upload: souvik-halder

Post on 12-Apr-2015

15 views

Category:

Documents


0 download

DESCRIPTION

Linux Tricks

TRANSCRIPT

Page 1: Linux Tricks

1.  Everything in Linux is a file including the hardware and even the directories.

2. # : Denotes the super(root) user

3.  $ : Denotes the normal user

4.  /root: Denotes the super user’s directory

/home: Denotes the normal user’s directory.

5.  Switching between Terminals

§  Ctrl + Alt + F1-F6: Console login

§  Ctrl + Alt + F7: GUI login

6.  The Magic Tab: Instead of typing the whole filename if the unique pattern for a particular file is given then the remaining characters need not be typed and can be obtained automatically using the Tab button.

7.   ~(Tilde): Denotes the current user’s home directory

8.   Ctrl + Z: To stop a command that is working interactively without terminating it.

9.  Ctrl + C: To stop a command that is not responding. (Cancellation).

10.  Ctrl + D: To send the EOF( End of File) signal to a command normally when you see ‘>’.

11.  Ctrl + W: To erase the text you have entered a word at a time.

12.  Up arrow key: To redisplay the last executed command. The Down arrow key can be used to print the next command used after using the Up arrow key previously.

13.  The history command can be cleared using a simple option –c (clear).

14.  cd :   The cd command can be used trickily in the following ways:

cd : To switch to the home user

cd * : To change directory to the first file in the directory (only if the first file is a directory)

cd .. : To move back a folder

cd - : To return to the last directory you were in

15.  Files starting with a dot (.) are a hidden file.

16.   To view hidden files: ls -a

17.   ls: The ls command can be use trickily in the following ways:

ls -lR : To view a long list of all the files (which includes directories) and their subdirectories recursively .

ls *.* : To view a list of all the files with extensions only.

18.   ls -ll: Gives a long list in the following format

drwxr-xr-x 2 root root 4096 2010-04-29 05:17 bin where

drwxr-xr-x : permission where d stands for directory, rwx stands for owner privilege, r-x stands for the group privilege and r-x stands for others permission respectively.

Here r stands for read, w for write and x for executable.

2=> link count

root=>owner

root=>group

4096=> directory size

2010-04-29=>date of creation

05:17=> time of creation

bin=>directory file(in blue)

 

The color code of the files is as follows:

Page 2: Linux Tricks

Blue: Directory file

White: Normal file

Green: Executable file

Yellow: Device file

Magenta: Picture file

Cyan: link file

Red: Compressed file

File Symbol

-(Hyphen) : Normal file

d=directory

l=link file

b=Block device file

c=character device file

19.  Using the rm command: When used without any option the rm command deletes the file or directory ( option -rf) without any warning. A simple mistake like rm / somedir instead of rm /somedir can cause major chaos and delete the entire content of the /(root) directory. Hence it is always advisable to use rm command with the -i(which prompts before removal) option. Also there is no undelete option in Linux.

20.  Copying hidden files: cp .* (copies hidden files only to a new destination)

21. dpkg -l : To get a list of all the installed packages.

23. Use of ‘ > ‘ and ‘ >> ‘ : The ‘ > ‘ symbol ( input redirector sign) can be used to add content to a file when used with the cat command. Whereas ‘ >> ‘ can be used to append to a file. If the ‘ >> ‘ symbol is not used and content is added to a file using only the ‘>’ symbol the previous content of the file is deleted and replaced with the new content.

e.g: $ touch text (creates an empty file)

$ cat >text

This is text’s text. ( Save the changes to the file using Ctrl +D)

$cat >> text

This is a new text. (Ctrl + D)

Output of the file:

This is text’s text.

This is a new text.

 

23.  To count the number of users logged in : who |wc –l

 

24.  cat:  The cat command can be used to trickly in the following way:

- To count no. of lines from a file : cat <filename> |wc -l

- To count no. of words from a file : cat <filename> |wc -w

- To count no. of characters from a file : cat <filename> |wc –c

 

25.  To search a term that returns a pattern: cat <filename> |grep [pattern]

 

26.  The ‘tr’ command: Used to translate the characters of a file.

tr ‘a-z’ ‘A-Z’ <text >text1 : The command for example is used to translate all the characters from lower case to upper case of the ‘text’ file and save the changes to a new file ‘text1′.

27.  File permission using chmod: ‘chmod’ can be used directly to change the file permission of files

Page 3: Linux Tricks

in a simple way by giving the permission for root, user and others in a numeric form where the numeric value are as follows:

r(read-only)=>4

w(write)=>2

x(executable)=>1

e.g. chmod 754 text will change the ownership of owner to read, write and executable, that of group to read and executable and that of others to read only of the text file.

28.  more: It is a filter for paging through text one screenful at a time.

Use it with any of the commands after the pipe symbol to increase readability.

e.g. ls -ll |more

29.  cron : Daemon to execute scheduled commands. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.

1 * * * * echo “hi” >/dev/tty1 displays the text “hi” after every 1 minute in tty1

.—————- minute (0 – 59)

| .————- hour (0 – 23)

| | .———- day of month (1 – 31)

| | | .——- month (1 – 12) OR jan,feb,mar,apr …

| | | | .—– day of week (0 – 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

* * * * * command to be executed

Source of example: Wikipedia

30.  fsck: Used for file system checking. On a non-journaling file system the fsck command can take a very long time to complete. Using it with the option -c displays a progress bar which doesn’t increase

the speed but lets you know how long you still have to wait for the process to complete.

e.g. fsck -C

31.  To find the path of the command: which command

e.g. which clear

32. Setting up alias: Enables a replacement of a word with another string. It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command

e.g. alias cls=’clear’ => For buffer alias of clear

33.  The du (disk usage) command can be used with the option -h to print the space occupied in human readable form. More specifically it can be used with the summation option (-s).

e.g. du -sh /home summarizes the total disk usage by the home directory in human readable form.

34.  Two or more commands can be combined with the && operator. However the succeeding command is executed if and only if the previous one is true.

e.g. ls && date lists the contents of the directory first and then gives the system date.

35.  Surfing the net in text only mode from the terminal: elinks [URL]

e.g: elinks www.google.com

Note that the elinks package has to be installed in the system.

36.  The ps command displays a great more deal of information than the kill command does.

37.  To extract a no. of lines from a file:

e.g head -n 4 abc.c is used to extract the first 4 lines of the file abc.c

e.g tail -n 4 abc.c is used to extract the last 4 lines of the file abc.c

Page 4: Linux Tricks

38.  Any changes to a file might cause loss of important data unknowingly. Hence    Linux creates a file with the same name followed by ~ (Tilde) sign without the recent changes. This comes in really handy when playing with the configuration files as some sort of a backup is created.

39.   A variable can be defined with an ‘=’ operator. Now a long block of text can be assigned to the variable and brought into use repeatedly by just typing the variable name preceded by a $ sign instead of writing the whole chunk of text again and again.

e.g ldir=/home/my/Desktop/abc

cp abcd $ldir copies the file abcd to /home/my/Desktop/abc.

40. To find all the files in your home directory modified or created today:

e.g. find ~ -type f -mtime 0

For a continuation of this topic refer to our next stone Basic-command-line-tips-tricks-ii

This article is a continuation of our previous stone – 40 Basic Command Line Tips and Tricks. The terminal is a really powerful tool when it comes to Linux, anything and almost everything on Linux can be done via the command line. Therefore it is necessary for us to have a basic idea of all the important commands and a few really important options that come along with them.

1. BASH ( Bourne-Again SHell ) is the most common shell in Linux. It’s freeware shell.

cat /etc/shells -> To find the available shells in your system /bin/shell-name  -> For temporary changing of the shell

/bin/sh :  To change to the sh shell.

To return back to the bash shell : /bin/bash

2. To print your home directory location:

echo $HOME

3. To print colouful text

echo -e ” \ 033[31m Hello  World” Note : There is no space between the \ and 0Output : Hello World ( in Red )

Set foreground color:echo -e ” \ 033[3xm” ( where x = 0 – 7 ) Note : There is no space between the \ and 0Set background color :echo -e ” \ 033[4ym” ( where y = 0 – 7 ) Note : There is no space between the \ and 0

4. The sort command can be used to sort lines of text files. It can be used for sorting of both numbers and characters or words.

For example if your file myfile.txt contains the following data :

RajuKhanalaayush

If you want to sort it the following command gives you the sorted list

sort myfile.txtOutput :aayushKhanalRaju

5. The cut command is used for removing sections from each line of files. For instance consider a file myfile.txt with the following data

IIT2009009:Raju:KhanalIIT2009010:Pankaj:Bhansali

cut -c1-10 myfile.txtOutput :IIT2009009IIT2009010

cut -c4,8 myfile.txtOutput:2020

Page 5: Linux Tricks

cut -d: -f2 myfile.txtOutput:RajuPankaj

6. The paste command is used for the merging the lines of files.

paste <  file1 > < file2 >Output shows that the two files are combined line-by-line with tabs separating the two.

7. The join Command is used for joining lines of two files on a common field.

File1 data IIT2009009 30IIT2009010 40

File2 data :IIT2009009 40IIT2009010 50

join File1 File2Output :IIT2009009 30 40IIT2009010 40 50

Note : Make sure the files are in sorted order.

8. uniq command is used to omit the repeated lines.

Myfile.txt dataRaju KhanalRaju KhanalAayush Khanal

uniq -u myfile.txt -> For non-duplicated lines use the -u flag.Output :Aayush Khanal

uniq -c myfile.txt -> For counting the number of times each one appears -c flag is used.Output :2 Raju Khanal1 Aayush Khanal

9. spell : It is a spell checking program which prints each misspelled word on a line of its own. When used with the -n option it gives the line numbers before lines.

spell -n myfile..txt gives the line number and the misspelled word in the myfile..txt file.

10. finger command : The finger command displays information about the system users.

11. Say you want to add a user but don’t know the command to do it. Don’t worry with the power of the Linux command line you don’t have to mug up the commands. You can use the man command with the option -k to search by keyword user for relevant commands.Note : The man -k is equivalent to apropos command which is used to search the short manual page descriptions for keywords and display any matches.

12. The general forms of the sed command are as follows:

Substitution sed:  ‘s/regexp/replacement/g’ < file >Deletion sed:  ‘< start >,< end > d’ < file >

sed ‘s/raju/aayush/g’ myfile.txt :=> To change all occurrences of the word ‘raju’ to ‘aayush’ in the myfile.txt.txt filewhere “s” means substitute, and the “g” means make a global  change. If you leave off the “g” only the first occurrence on each line is changed

sed ’2,3d’ myfile.txt => To remove lines starting from line number 2 and ending in line number 3 including the third line

13. With the ‘awk’ command, you can substitute words from an input file’s lines for words in a template or perform calculations on numbers within a file.Ex : Consider a file with the following data

Raju is 57 Kg and Aayush is 60 Kg.Pankaj is 60 Kg and Pramod is 55 Kg.

awk ‘{ print $1 ” and ” $6  }’ < filename >Output :Raju and AayushPankaj and Pramod

awk ‘{ print “Average of both are ” ( $3 + $8 ) / 2 }’ < filename >Output :

Page 6: Linux Tricks

Average of both are 58.5Average of both are 57.5

14. expr is used for evaluating expressions.

Ex: expr 10 + 3 gives 13.

Note: For multiplication it is \* and not *.

15. bc , the , Linux calculator program can be used to perform arithmetic calculation.For instance if you want to multiply 10 and 3, just use the bc command and then give the expression 10 * 3 to get the desired output.Note : In this case the multiplication symbol is the traditional “*” instead of “\*” as we used in expr .

16. whatis is a command that displays the manual page descriptions. If you explore your Linux system, you will find a lot of programs and you may not know what they do.

Ex : whatis catOutput :cat (1) – concatenate files and print on the standard output.

Note : man -f cat gives the same output.

17. The tee command reads from standard input and write to standard output and files.

ls -l | tee dir_list => For directing the output of ls -l to dir_list file.

When used with the -a option it is used for appending ( remember the >> operator )

18. zcat will read gzipped files without needing to uncompress them first.

zcat myfile.txt.gz => To read the gzipped file myfile.txt.gz

19. The file command is used to determine the file type.A directory known as abc if cannot be identified from its color, can be identified from the file command.

file abcOutput :abc: directory

20. The diff command is used to compare files line by line. When used with the -y option ( side by side ) the output is obtained in two columns differentiating the two files increasing readability.Note : The sign “|” in the output indicates that there is a difference whereas the sign “>” and “<” indicate what is left out or added.

21. The cat command provides three useful options -v for displaying non-printing characters , -t prints “^I” for each Tab in the file and -e prints a “$” at the end of each line to indicate a NULL character.

cat -vet < filename >

22. mkdir used with the -p option creates nested directories.

23. The tac command concatenates and prints files in reverse.

24. The dict command can be used to find out the meaning of any word.

dict encumberedgives you the meaning, thesarus words and sample sentences of the word encumbered.

Note: The dict package is neccessary for the usage of the dict command.

25. The style command analyses the surface characteristics of a document giving the sentence info, word usage, sentence beginnings and so on.

26. The locate command can be used to find files by name. It is an alternative to the find command and can be really useful.

locate < filename > gives the path of that filename.

For more on the find command visit our stone ‘Mastering the Find Command‘.

Page 7: Linux Tricks

It is often said that there is never any justification for things being complex when they could be simple. Most of the time we spend a lot of effort trying to a complete a task which in fact can be accomplished by a single stroke in the command line. For instance, to remove all the empty files in a graphical environment, you have to go through the search options, select the files and finally delete them. Whilst if you working on a terminal the same task can be done via a single command.

Generally when we talk about command line, we start relating command-line stuff with geek stuffs which is not true. All I am saying is that, it is worth trying to learn a few commands if it saves your time and reduces complexities.

So, if you go through this article, you will eventually appreciate the wonders of the shell commands.

1. Extract specific field from a colon delimited file and save it to another file

# cut -d: -f 2,5 sourcefile.txt > targetfile.txt

This is really useful when the source file has hundreds of lines.

2. Sort a file in ascending order removing duplicate entries and save the result to a file

# sort -u -o target.txt sourcefile.txt

3. Sort specific field from a colon delimited file removing duplicate entries and save the result to a file

# sort -t: -u -k 2 -o target.txt sourcefile.txt ( to sort in descending order use -r option )

4. Display the largest file (in size) of the current directory.

# du -s * | sort -nr | head -1

or

# ls -al | sort -nr -k5 | head -1

( to display top 5 largest files in size, use: head -5 )

5. Combine two files and save the result in a file

# join file1.txt file2.txt > target.txt

6. Remove all HTML tags from a file

# awk ‘{gsub(“<[^>]*>”, “”)}1′ filename

7. Display the difference between two files

# diff -w file1.txt file2.txt

8. Change the contents of a file to all UPPER-CASE

# tr ‘[:lower:]‘ ‘[:upper:]‘ < test.txt > result.txt

Similarly, to all lower-case

# tr ‘[:upper:]‘ ‘[:lower:]‘ < test.txt > result.txt

9. Remove one or more new lines with a single new line and save the result to a file

# tr -s ‘\n’ < test.txt  > result.txt

10. Remove one or more blank space with a single space and save the result to a file

# tr -s ‘[:space:]‘ ‘\ ‘ < test > result.txt

11. Remove all non-printable characters from a file

# tr -cd “[:print:]” < test

12. Create a list of words from a file

# tr -cs “[:alpha:]” “\n” < test > targetfile

13. Delete all the empty files from your home folder

# find /home -empty -exec rm {} \;

Page 8: Linux Tricks

14. Pick a random line from a file

# shuf -n1 filename.txt

15. find all the archive files and extract them

# find /home -type f -name “*.tar.gz” -print | xargs tar -xvzf

16. find all the pdf files and archive it

# find /home -type f -name “*.doc” -print | xargs tar -cvzf /tmp/documents.tar.gz

17. find files that are not modified in last x time

# find /home -type f -name “aaa” -mtime -10

Here if we want files to be more than 100 Mb, we use -size +100M

# find /home -type f -name “aaa” -size +100M -mtime -10

18. find files that were last accessed 2 to 10 minutes ago

# find /home -atime +2 -atime -10

19. find files newer than a specified file

# find -newer mydoc.doc

20. find files that was accessed x days after its status was last changed

# find -used 2

21. find files owned by

a. user

# find /home -user rabi

to find files that do not belong to any user

# find /home -nouser

b. group

# find /home -group fortystones

to find files that do not belong to any group

# find /home -nogroup

22. To download all files of a particular format, like all pdfs

# wget -r -l1 -A.pdf –no-parent http://url-to-webpage-with-pdfs/

( -A option to accept the specified format ie .pdf)

23. Download an entire website

# wget -r http://site-name.com

24. Download a given HTML page with inlined images, sounds, and referenced stylesheets to properly display the HTML page.

# wget -p http://<site>/1.html

25. List all the URLs in a file and download the contents of the URLs with a single command

# wget -i files_with_URLs.txt

Linux has more than 650 commands and every command has its own set of options all performing different operations. Going through each and every one of these commands will be a very tedious task. However limiting yourself to only a few of them is never an option. The trick here to learning all these commands, is to categorise them according to their function. By doing this, you will know atleast the basic commands and have some measure of control over the Linux command line.

When you go through these commands, you will be able to perform different function as per your need in the Linux command line.

Basic Commands Editor User Account

Page 9: Linux Tricks

Network Commands Archive Commands Help Commands Package Management Utilities Process Commands

Basic Commands

The ‘must’ know commands fall in this category. I have distributed the commands into two sub categories:  Directory commands and File commands.

Directory Commands

o pwd : Print working directoryo mkdir : Create directorieso cd : Change the current directoryo rmdir : Remove directories

File Commands

o ls : List directory contentso rm : Remove fileso cp : Copy files from a source to the

same or different target(s).o mv : Move file to different targets.o cat : Read one or more files and print

them to standard output. If you need to

view  contents of a short file, cat is recommended.

o cmp: Compare two files byte by byte.o wc: Print the number of new lines,

words, and bytes in files.o du : Estimate disk usage of each file and

recursively for directories.o find: Search for files in directory

hierarchy, e.g. find notes.txto grep: Print lines matching a pattern,e.g.

grep –i topic notes.txt (topic is the pattern)

o sort: Sort lines of text files

Editor

Every Linux program is an executable file. For instance, the cp command is provided by the file in /bin/sh which holds the list of machine instructions. Similarly, if you are installing a package , let’s say vsftpd, your focus will be modifying its configuration file , vsftpd.conf present in /etc directory. This is where you will be using editors.

I use ‘Vim’ frequently. It’s an advanced text editor that comes with a more complete feature than the ‘Vi’ text editor. The other text editors are: nano, vi, kate, (KDE Advanced Text Editor), gedit (graphical user interface).

e.g.  vim  rabi.c ( vim filename ).

User Account

In linux, you can say that using the ‘root’ account is like having the powers of God. You will have access to almost each and every file(configuration files, system , text files etc)  with no interruption and restriction.  You need to be very careful while doing work as the root (super user). Therefore, managing user accounts and groups is an essential part of a system administrator.

For example, an organization ABC has three departments: Marketing, Technical and Account, each department having 3-4 employees. The organization demands you to verify the users of marketing,  technical and account departments so that the employees of each group will be able to view his/her own department file.

Given a scenario, if you know how to manage these accounts, you can easily set permissions for the users mentioned above.  If not, these commands are essential for the task.

useradd : for creating user account.

This command can be executed by administrators only. On debian, you should use adduser. For other options like adding expiry date, home directory etc refer man useradd.

Page 10: Linux Tricks

passwd : for changing user password.

If the user has set password before, he/she will be prompted for the first password whereas superuser is permitted to bypass the step so that forgotten passwords may be changed.

You can find advices on how to choose a strong password on http://en.wikipedia.org/wiki/Password_strength

usermod : modify user accoun. userdel : delete a user account and related

files

This command can be executed by administrators only.

groupadd : create a new group groupdel : delete the group and entries

referring to the group groupmod : modify a group definition on the

system chmod : modify properties for users chown : change file owner and group chgrp : change group ownership

Network Commands

Linux is predominantly known for its use in servers. In 2009 it held a server market share ranging between 20–40%(source : wikipedia). One should know the commands to check the ip address, download files from the net, get DNS, etc.

wget   : a non-interactive network downloader

Even if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved.   The server will instruct to continue to download from where it  it left off.

$ wget url-for-file

ping  : send ICMP ECHO_REQUEST to network hosts, you will get back ICMP packet if the host responds.  This command is useful when you are in a doubt whether your computer  is connected or not.

$ ping IP or host name

hostname  : show or set  the system’s host name

dnsdomainname : show the system’s DNS domain name

netstat : displays the status of ports ie. which ports are open, closed,       waiting for connections. It displays the contents of /proc/net file.

ifconfig : configure a network interface, or to display their current configuration. It is also useful to get the information about IP address, Subnet Mask,set remote IP address , Netmask etc.

ifup : bring a network interface up

ifdown : take a network interface down

Archive Commands

You want to install a package from its source code. You find out that the source code of the package is archived in a file xxx.tar. In this situation, the command-line utility ‘tar’ proves to be a vital resource for you. The ‘tar’ is probably the most popular Linux backup utility. If the ‘tar’ file is compressed with the compression utility like ‘bzip’ or ‘gzip’, the resulting file is the famous ‘tarballs’ which is a common method to deliver software installation archives.

tar : an archiving program designed to store and extract files from an archive known as a tarfile.

Options :

-c : create a new archive

-r : append files to the end of an archive

-t : list the contents of an archive

-u : only append files that are newer than copy in archive

-x : extract files from an archive

-C : change to directory Dir

Page 11: Linux Tricks

-j : filter archive through bzip2,  use  to  decompress  .bz2  files.

-v : verbosely list files processed

-f : use  archive  file

-z : filter the archive through gzip

Examples: tar  -xvf  test.tar    ( extract foo.tar to the current location)

tar -xvzf  test.tar.gz  ( extract gzipped test.tar.gz )

tar  -cvf test.tar    foo/ ( compress the contents of foo folder to foo.tar )

Help commands

There are manual pages for almost all the commands of Linux. You can access the manual pages using man command. The man command offers documentation of the command.  If you type:

$ man ls

You will be seeing the manual page of ls with its name, synopsis, description, author, copyright etc. Remember, there is a manual page for the man command itself.

If you desire to have a brief reference of the command, use -help option with the command.  $ ls -help

You can even use info command to have a quick overview of the command.   $ info ls

Remember, that memorizing all the commands in Linux along with all its options is a very difficult job. So memorise the command and options which has frequent usage and leave the rest to the HELP commands.

Package Management Utilities

On RED HAT, SUSE, and many similar Linux distributions, the RPM Package Manager (RPM) format is used. Ubuntu and Debian, however, uses

the Debian Pacakge (DEB) format. Therefore, I have categorised it into two, one for RPM and the other for Debian.

For RPM format, the rpm and yum is prefered.

rpm  options  rpm-package-name (use man rpm for further more information) The -q option tells you if a package is already installed, and the -qa option displays a list of all installed packages.

-qa : List all installed RPM applications -qf : Lists applications that own filename -qR : Lists applications on which this application depends -qi : Displays all application information -qd : Lists only documentation files in the application -qc : Lists only configuration files in the application

If you add p qualifier to the above options, gives information about specific package. For e.g. -qpl : Lists files in the RPM package

Yum (Yellowdog Update modifier) -yum is an automatic updater and package installer/remover for rpm systems. It automatically computes dependencies and figures out what things should occur to install packages. You need to install yum in your Linux system.

yum    command    package-name

e.g. $yum install package-name

Its configuration file is /etc/yum.

For Debian packages, Advanced Package Tool (APT) and Debian Package Tool (dpkg) is preferred.

apt   command   package-name use apt-get install package-name to install a package.

Similarly, if you want to upgrade a package use apt-get upgrade package-name. With no package specified, apt-get with the upgrade command will upgrade your entire system for FTP site, or CD. You can find configuration files in /etc/apt. There are sources.list, apt.conf files to look for.

dpkg(Debian package tool) is another method to install a binary file with the format .deb. To install , type  $dpkg   -i  xxxx.deb

Page 12: Linux Tricks

To remove, $dpkg -r xxxx.deb. 

Process commands

In order to execute a command in the background, place an ampersand(&) on the command line at the end of the command. A user job number(placed in brackets) and a system process number are displayed. A system process number is the number by which the system identifies the job whereas a user job number is the number by which the user identifies the job.

$ sudo cp -rf * ~/ss &

[1]   9144

$

jobs : lists the jobs being run at the background

$jobs

[1]-  Running   sudo  cp  -rf  *  ~/ss  &

[2]+  Running   sudo  cp  -rf  *  ~/yy &

The ‘+‘ sign indicates the job currently being processed , ‘-’ sign indicates the upcoming jobs to be executed. The ‘% ‘ used with the job number refrences a job. e.g. Used in fg.

fg : a process running in the background will be processed in the foreground

$ fg % 2

cat  *.cpp  > mytext

$

kill : cancels a job running in the background, it takes argument either the user job number or the system process number.

$jobs

[1]   +  Running    cp  *.c  > mytext

[2]  - Running    cp  *.dat >>mytext

$kill %2

bg: places a suspended job in the background

$ cat *.cpp > mytext

^Z

$bg

( Ctrl + Z  will suspend the process running at the moment )

ps : reports a snapshot of the current processes top : displays Linux tasks at : executes commands at a specified time.

$ at  8:00

at >  echo “HI” > /dev/tty1

(Press ‘ctrl + d’ to return to the command line. This will display the message in tty1 at 8′o clock.)

To view the schedule : $ atq To cancel a job : $atrm 5 [job ID] crontab :crontab is a file which contains the

schedule of entries to run at specified times. shutdown : bring the system down

o -r Requests that the system be rebooted after it has been brought down.

o -c Cancels a running shutdown.

Other commands

whoami : displays the login name of the current effective user.

logname : print user´s login name quota : display disk usage and limits, e.g $

quota -v su : switch to super user or change user ID which : returns the pathnames of the files

which would be executed in the current environment.

Type $which ls, you will get /bin/ls.

Page 13: Linux Tricks

If you have been using any of the Linux distributions or intend to, you must be aware of the terminologies related to it. Therefore, with an objective to familiarize you with the new terms or the terms that you have heard of, I have tried my best to compile these 40 basic terminologies related to Linux.

Alien

Alien is a computer program that supports conversion between different Linux package formats. For example, it helps conversion between Linux Standard Base, RPM, deb, Stampede (.slp), Solaris (.pkg) and Slackware (.tgz) packages. It is also capable of automatically installing the generated packages, and can try to convert the installation scripts included in the archive as well.

# alien --to-rpm --scripts ./test.deb (test.deb converted to test.rpm)

Apache HTTP Server

The Apache HTTP Server commonly referred to as Apache is an open-source HTTP server for modern operating systems including Linux and Windows NT. It is also notable for playing a key role in the initial growth of the World Wide Web.

Now the application is available for a wide variety of OS, including UNIX, GNU, FreeBSD, Solaris, Novell NetWare, Mac OS X, Microsoft Windows, OS/2, TPF, and eComStation.

APT

The Advanced Packaging Tool, or APT, is a free user interface that works with core libraries to handle the installation and removal of software on the Debian GNU/Linux distribution and its variants.

In the process of managing , APT automates the retrieval, configuration and installation of software packages, either from binary files or by compiling source code.

APT was originally designed as a front-end for dpkg to work with Debian’s .deb packages, but it has since been modified to also work with the RPM Package Manager system via apt-rpm.

Console

A console is a computer program which acts as a medium to communicate with the computer via a text-only computer interface, such as a text terminal ot the command line interface of some operating systems (Unix etc).

In some GUI operating systems, such as Microsoft Windows, it is included as text-based interface.

Daemon

A daemon is basically a computer program that runs in a background and is normally initiated as background processes. They come in handy while installing packages.

Daemons are normally executed at boot time. They often serve the function of responding to network requests, configure hardware, and run scheduled tasks.

This term was coined by the programmers of MIT’s Project MAC.

e.g.  cron, httpd, chttpd, ftpd etc.

Debian

Among most Linux distributions, there are basically two major software packaging, RPM and DEB. A Debian package will automatically resolve dependencies, installing any other needed packages instead of simply reporting their absence, like RPM does.

Debian Packages are named with the software name, the version number, and the .deb extension.

The DEB format is much more capable than its RPM counterpart.

Dependencies

When referring to packages, dependencies are requirements that exist between packages.

For example, if you are installing a package, it may require files that are installed by another package. Therefore the other package must be installed or

Page 14: Linux Tricks

else the previous package will have unresolved dependencies.

RPM will not normally allow packages with unresolved dependencies to be installed.

DHCP

The Dynamic Host Configuration Protocol (DHCP) is an auto-configuration protocol used on IP networks.  Auto-configuration in a sense that DHCP allows a computer to be configured automatically, eliminating the need for intervention by a network administrator.

It also provides a central database for keeping track of computers that have been connected to the network. This prevents two computers from accidentally being configured with the same IP address.

dpkg

Debian Package Tool (dpkg) is the software which is used to install, remove, and provide information about .deb packages.

Firewall

Firewall is a device or set of devices and protocols that separates network traffic, usually on the basis of a set of rules to allow only certain traffic through

GCC

The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. The compiler handles C programming language and now extended to compile C++.   GCC has been adopted as the standard compiler by GNU/Linux, the BSD family and Mac OS X.

GCC is also available for most embedded platforms, for example Symbian, AMCC and Freescale Power Architecture-based chips.

GNOME

GNU Network Object Model Environment is a desktop environment—a graphical user interface

that runs on top of a computer operating system—composed entirely of free and opens source software. GNOME is part of the GNU Project.

It can be used with GNU/Linux

GNU

GNU is a Unix-like computer operating system developed by the GNU project.  It is free software and contains no UNIX code.

GNU Compiler Collection (GCC), the GNU Binary Utilities (binutils), the bash shell, the GNU C library (glibc), and GNU Core Utilities (coreutils) are included in this OS.

GNU Binutils

The GNU Binary Utilities, or binutils, is a collection of programming tools for the manipulation of object code in various object file formats.

GNU Core Utilities

The GNU Core Utilities or coreutils is a package of GNU software containing many of the basic tools, such as cat, ls, and rm, needed for Unix-like operating systems.

Program include in core utensils : chcon, chgrp, chown, chmod ,cp ,ls, mkdir , mv , rmdir etc.

GNU GRUB  (Grand Unified Boot Loader)

GNU GRUB  is a boot loader which enables a user to have multiple operating systems. The user can choose which OS to run when the computer starts.

The GNU operating system uses GNU GRUB as its boot loader.

HTTPS

Hypertext Transfer Protocol Secure (HTTPS) is a combination of the Hypertext Transfer Protocol with the SSL/TLS protocol to provide encryption

Page 15: Linux Tricks

and secure (website security testing) identification of the server.

It uses port 443 whereas HTTP uses port 80.

HTTPS connections are often used for payment transactions on the World Wide Web and for sensitive transactions in corporate information systems.

ipkg

ipkg, or the Itsy Package Management System, is a package management system designed for embedded devices that tries to resemble Debian’s dpkg.

It is used in the operating system for the Linksys NSLU2 (Optware), in OpenWRT, Openmoko, WebOS, Gumstix, the iPAQ, QNAP NASes, Synology NASes and elsewhere.

KDE

KDE is an international free software community producing an integrated set of cross-platform applications designed to run on Linux, FreeBSD, Windows, Solaris and Mac OS X systems.

It is best known for desktop environment provided as the default working environment on many Linux distributions, such as openSUSE, Mandriva Linux, Kubuntu, Red Flag Linux, and Pardus.

Kernel

Kernel is a bridge between applications and the actual data processing done at the hardware level. A kernel can provide the lowest-level abstraction layer for the resources (especially processors and I/O devices).

In computing, the kernel is the central component of most computer operating systems.

Kopete

Kopete is a multi-protocol, free software instant messaging client. Although it can run in numerous environments, it was designed for and integrates with the KDE desktop environment.

Linux

Linux refers to the family of Unix-like computer operating systems using the Linux kernel. Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers.

Linux Kernel (released under the GNU General Public License version 2 )

The Linux kernel is an operating system kernel used by the Linux family. It is one of the most prominent examples of free and open source software.

The Linux kernel was initially conceived and created by Finnish computer science student Linus Torvalds in 1991. Many Linux distributions have been released based upon the Linux kernel.

Nautilus

Nautilus is the official file manager for the GNOME desktop. The name is a play on words, evoking the shell of a nautilus to represent an operating system shell.

OpenSSL

OpenSSL is an open source implementation of the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols. The core library (written in the C programming language) implements the basic cryptographic functions and provides various utility functions.

OpenSSL is based on SSLeay.

Versions are available for most operating systems including Solaris, Linux, Mac OS X , OpenVMS and Microsoft Windows.

Package

A software package refers to computer software packaged in an archive format to be installed by a package management system or a self-sufficient installer.

Page 16: Linux Tricks

Linux distributions are normally segmented into packages. Each package contains a specific application or service.

Examples of packages: a collection of fonts, or a web browser.

Package Management System

A package management system is a collection of tools to automate the process of installing, upgrading, configuring, and removing software packages from a computer .IT is sometimes incorrectly referred to as an installer.

e.g.  dpkg, used originally by Debian and now by other systems, uses the .deb format ,

the RPM Package Manager for Red Hat,

YUM, which is used by Fedora, Red Hat Enterprise Linux  5, and Yellow Dog Linux

Pacman for Arch Linux, Frugalware and Lunar Linux, Minix

Smart Package Manager, used by CCux Linux

PETget, used by Puppy Linux

Paging

In computer operating systems there are various ways in which the operating system can store and retrieve data from secondary storage for use in main memory. One such memory management scheme is referred to as paging.

Repository

A repository is a central place where multiple databases or files are located for distribution over a network, or a repository can be a location that is directly accessible to the user without having to travel across a network.

In Linux terms, A central area for users to collect RPMs/DEBs/etc from.

rpm

RPM Package Manager is a package management system. The name RPM refers to two things: software packaged in the .rpm file format, and the package manager itself.

RPM was intended primarily for GNU/Linux distributions; the file format RPM is the baseline package format of the Linux Standard Base.

RPM has been criticized for a lack of consistency in package names and content which can make automatic dependency handling difficult.

Shell

A shell is a piece of software that provides an interface for users to an operating system which provides access to the services of a kernel. Operating system shells generally fall into one of two categories: command-line and graphical.

Command-line shells provide a command-line interface (CLI) to the operating system, while graphical shells provide a graphical user interface (GUI).

SELinux

Security-Enhanced Linux (SELinux) is a Linux feature that provides a mechanism for supporting access control security policies, including U.S. Department of Defense style mandatory access controls, through the use of Linux Security Modules (LSM) in the Linux kernel.

It is not a Linux distribution, but rather a set of modifications that can be applied to Unix-like operating system kernels, such as Linux.

Synaptic Packet Manager

Synaptic Packet Manager is a computer program which is a GTK+ graphical user interface and front-end to the Advanced Packaging Tool for the Debian packages which is used to install, remove and upgrade software packages.

Desktop environments such as KDE and GNOME have programs that pop up a password query box before allowing a user to run commands that would typically require such access.

Page 17: Linux Tricks

su ( switch user or substitute user)

su is a Linux command used to run the shell of another user without logging out.

It is commonly used to change to root user permissions for administrative work without logging off.

sudo

sudo (super user do) is a program for Unix-like operating systems such as BSD, Mac OS X, and Linux that allows users to run programs with the security privileges of another user (normally the system’s superuser) in a secure manner.

Swap

Linux and other Unix-like operating systems use the term “swap” to describe both the act of moving memory pages between RAM and disk, and the region of a disk where the pages are stored on. It is common to use a whole partition of a hard disk for swapping. These partitions are called swap partitions.

Terminal Emulator (tty)

A terminal emulator is a program that emulates a video terminal within some other display architecture. On Unix-like operating systems it is common to have one or more terminal windows connected to the local machine.

A terminal emulator inside a graphical user interface is often called a terminal window.

Web Server

A web server is a computer program that delivers content, such as web pages, using the Hypertext Transfer Protocol (HTTP), over the World Wide Web.

The term web server can also refer to the computer or virtual machine running the program

X Window System (commonly X or X11)

The X Window System is a computer software system and network protocol that provides a graphical user interface (GUI) for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X.

X originated at MIT in 1984.

YUM

The Yellowdog Updater, Modified (YUM) is an open-source command-line package-management utility for RPM-compatible Linux operating systems and has been released under the GNU General Public License.  There are several other tools which provide graphical user interfaces to yum functionality.