Everything in Linux

Everything in Linux

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:

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 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

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

?

?

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

·?????? Network Commands

·?????? Archive Commands

·?????? Help Commands

·?????? Package Management Utilities

·?????? Process Commands

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

·?????? ?

o?? pwd : Print working directory

o?? mkdir :? Create directories

o?? cd : Change the current directory

o?? rmdir ? : Remove directories

·?????? ?

o?? ls : List directory contents

o?? rm : Remove files

o?? 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.txt

o?? grep: Print lines matching a pattern,e.g.?grep –i topic notes.txt?(topic is the pattern)

o?? sort: Sort lines of text files

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 ).

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.

·?????? 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?https://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

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

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

-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 )

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, copyrightetc. 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 theHELP?commands.

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

To remove,?$dpkg -r xxxx.deb.?

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 numberare 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.

·?????? 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.

Subscribe to?fortystones.?

?

要查看或添加评论,请登录

Shamsul Huda的更多文章

社区洞察

其他会员也浏览了