Você está na página 1de 19

Home About

Linux from beginning My diary of learning linux from day one September 30, 2008 Linux Command 14 = ifconfig, ifup, ifdown, ping, traceroute, host, dig Posted by linuxlibrary under Uncategorized | Tags: dig, host, ifconfig, ifdown, ifup, linux, linux command, ping, traceroute | Leave a Comment 1) ifconfig = allows the operating system to setup network interfaces and allow the user to view information about the configured network interfaces Examples ifconfig View the network settings on the Ethernet adapter currently used. ifconfig eth0 View the network settings on the first Ethernet adapter installed in the computer. ifconfig -a Display into on all network interfaces on server, active or inactive. ifconfig eth0 down If eth0 exists would take it down causing it cannot send or receive any information. ifconfig eth0 up If eth0 exists and in the down state would return it back to the up state allowing to to send and receive information. ifconfig eth0 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255 Assign eth0 with the above values for IP, netmask and broadcast address. . 2) ifup = bring a network interface up ifup eth0 bring up interface eth0 . 3) ifdown = bring a network interfacedown ifdown eth2 bring down interface eth2 . 4) ping = ping allows a user to ping another network IP address. This can help determine if the network is able to communicate with the network. Example: ping gmail.com Would ping the gmailhost .com to see if it is alive. ping gmail.com -c 1 Would ping the hgmailost .com once and return to the command line . 5) traceroute = print the route packets take to network host Examples:

$ traceroute google.co.in Trace the route for Google Server. $ traceroute -v 192.168.12.1 Show more details. $ traceroute -n server Print the HOP Address in numeric form. $ traceroute -I server Use ICMP ECHO instead of UDP datagrams. $ traceroute -i eth1 server Use eth1 for send the probe packets. $ traceroute server 100 Sent 100 Bytes packet instead of default 40 Bytes packet. 6) host = simple utility for performing DNS (Domain Name Service) lookups. It is normally used to convert names to IP addresses and vice versa Examples: $ host google.com Show the IP Address of Google.com. $ host -v google.com Show detailed output. $ host -a google.com Show more details. $ host 127.0.0.1 Do reverse lookup and Show the host name. $ host -l mydomain.com List all hosts available in MyDomain. . 7) dig = DNS lookup utility Ecamples: dig yahoo.com dig 66.94.234.13 dig -x 192.168.52. dig -t ANY yahoo.com September 29, 2008 Linux Command 13 jobs, bg, fg, nice, renice, at, top Posted by linuxlibrary under Uncategorized | Tags: at, bg, fg, jobs, linux command, nice, renice, top | Leave a Comment 1) jobs = lists the jobs that you are running in the background and in the foreground Syntax jobs [-p | -l] [-n] [-p] [-x] [job id] If the prompt is returned with no information no jobs are present jobs -p : list only the PID of process group leader jobs -l : list only jobs that have change status since last notified by their status jobs -r : resrict output to running jobs jobs s : restrict output to stopped jobs . 2) bg = place a job in background Normally user can run a job in background, by adding & at end of the command (ex: sleep 10 &). bg is a shell command. It is used to move a job from foreground to the background, as if it had been started with `&. If JOB is not present, the shells notion of the current job is used. Examples (follow all the steps below)

a) $ sleep 100 Start a dummy job in foreground. (sleep = waits a x amount of second) Press Ctrl+z to stop the current job. b) $ bg Move the last stopped job to background. c) $ sleep 150 Dummy job 1 Press Ctrl+z to stop the current job. d) $ sleep 140 Dummy job 2 Press Ctrl+z to stop the current job. e) $ sleep 130 Dummy job 3 Press Ctrl+z to stop the current job. f) $ jobs List all active jobs. g) $ bg 2 Move the 2nd active job to background. . .3) fg = continues a stopped job by running it in the foreground Examples fg Typing fg alone will resume the first job were it was left off. fg 1 specifying the job (in this case 1) will resume that particular job. The job id can be determined by running bg . 4) nice = run a command with modified priority nice command is used to run the given command with its scheduling priority adjusted. Priority range goes from -20 (highest priority) to 19 (lowest priority). Examples: $ nice Prints the current priority value. $ nice ls Increment the priority value of the ls command by 10 (Default value) and run. $ nice -n 5 ls Increment the priority value of the ls command by 5 and run. # nice -n -2 ls Decrement the priority value of the ls command by -2 and run. NOTE: Incrementing the priority value will reduce the priority level and vice versa. Priority range is -20 (high) to 19 (low). . 5) renice = renice is used to alters the scheduling priority of one or more running processes, priority range goes from -20 (highest priority) to 19 (lowest priority). Examples: $ renice +1 123 Increment the priority value of a process, which process ID is 123. # renice +1 123 Decrement the priority value of a process, which process ID is 123. (Root only can decrement ). $ renice +1 -p 123 -p 200 Same as above. Here no. of process is 2. $ renice +1 -u sbharathi Increment the priority value of all processes, which is owned by a user (sbharathi). $ renice +1 -g backup Increment the priority value of all processes, which is owned by a group (backup). NOTE: Incrementing the priority value will reduce the priority level

and vice versa. Priority range is -20 (high) to 19 (low). . 6) at = schedules a command to be ran at a particular time, such as a print job late at night Syntax at - executes commands at a specified time. atq - lists the users pending jobs, unless the user is the superuser; in that case, everybodys jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, job class. atrm - deletes jobs, identified by their job number. batch - executes commands when system load levels permit; in other words, when the load average drops below 1.5, or the value specified in the invocation of atrun. Examples at -m 01:35 < atjob = Run the commands listed in the atjob file at 1:35AM, in addition all output that is generated from job mail to the user running the task. When this command has been successfully enter you should receive a prompt similar to the below example. commands will be executed using /bin/csh job 1072250520.a at Wed Dec 24 00:22:00 2003 at -l = This command will list each of the scheduled jobs as seen below. 1072250520.a Wed Dec 24 00:22:00 2003 at -r 1072250520.a = Deletes the job just created. or atrm 23 = Deletes job 23. If you wish to create a job that is repeated you could modify the file that executes the commands with another command that recreates the job or better yet use the crontab command. Note: Performing just the at command at the prompt will give you an error Garbled Time, this is a standard error message if no switch or time setting is given. . 7) top = provide information (frequently refreshed) about the most CPU-intensive processes currently running Description of the fields a: PID Process Id The tasks unique process ID, which periodically wraps, though never restarting at zero. b: PPID Parent Process Pid The process ID of a tasks parent. c: RUSER Real User Name The real user name of the tasks owner. d: UID User Id The effective user ID of the tasks owner. e: USER User Name The effective user name of the tasks owner. f: GROUP Group Name The effective group name of the tasks owner. g: TTY Controlling Tty The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case youll see ? displayed. h: PR Priority The priority of the task. i: NI Nice value The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a tasks dispatchability./dd>

j: P Last used CPU (SMP) A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time). k: %CPU CPU usage The tasks share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if Irix mode is Off, top will operate in Solaris mode where a tasks cpu usage will be divided by the total number of CPUs. You toggle Irix/Solaris modes with the I interactive command. l: TIME CPU Time Total CPU time the task has used since it started. When Cumulative mode is On, each process is listed with the cpu time that it and its dead children has used. You toggle Cumulative mode with S, which is a command-line option and an interactive command. See the S interactive command for additional information regarding this mode. m: TIME+ CPU Time, hundredths The same as TIME, but reflecting more granularity through hundredths of a second. n: %MEM Memory usage (RES) A tasks currently used share of available physical memory. o: VIRT Virtual Image (kb) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. VIRT = SWAP + RES. p: SWAP Swapped size (kb) The swapped out portion of a tasks total virtual memory image. q: RES Resident size (kb) The non-swapped physical memory a task has used. RES = CODE + DATA. r: CODE Code size (kb) The amount of physical memory devoted to executable code, also known as the text resident set size or TRS. s: DATA Data+Stack size (kb) The amount of physical memory devoted to other than executable code, also known as the data resident set size or DRS. t: SHR Shared Mem size (kb) The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes. u: nFLT Page Fault count The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available. v: nDRT Dirty Pages count The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page. w: S Process Status The status of the task which can be one of: D = uninterruptible sleep R = running S = sleeping T = traced or stopped Z = zombieTasks shown as running should be more properly thought of as ready to run their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on tops delay interval and nice value. x: Command Command line or Program name Display the command line used to start a task or the name of the associated program. You toggle between command line and name with c, which is both a command-line option and an interactive command.When youve chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in parentheses, as in this example:

( mdrecoveryd ) Either form of display is subject to potential truncation if its too long to fit in this fields current width. That width depends upon other fields selected, their order and the current screen width. Note: The Command field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines. y: WCHAN Sleeping in Function Depending on the availability of the kernel link map (System.map), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash (-) in this column.Note: By displaying this field, tops own working set will be increased by over 700Kb. Your only means of reducing that overhead will be to stop and restart top. z: Flags Task Flags This column represents the tasks current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in . Less formal documentation can also be found on the Fields select and Order fields screens. . Interactive commands While top is running you may issue some options that will interact immediately with top these options are: h Help, displays a summary of command that will modify the behavior of top k Kills a process, you will be able to kill only your own processes, unless you are running top as root n Once this command is entered top will ask you how many lines you want on your screen, if you enter 0 top will display as much as it can q Exits top r Change the priority of a process, as well as with k you will only be able to act on your own processes unless you are root W Writes the current configuration to your personal configuration file, which is $HOME/.toprc

September 28, 2008 Linux Command 12 ps, ptree, pgrep, pidof, pkill, kill, killall Posted by linuxlibrary under Uncategorized | Tags: kill, killall, linux command, pgrep, pidof, pkill, ps, ptree | 1 Comment 1) ps = report process status ps : typing ps alone would list the current running processes ps -u username : to search processes run by a certain user ps ag : to get information about all running process ps aux : to display the owner of the processes along with the processes ps ax | grep processname : to see if a particular process is running or not . 2) ptree : to display a tree of processeses pstree -p | less : also display the pid of the process .

3) pgrep : look up or signal processes based on name and other attributes pgrep sshd : to list the processes called sshd pgrep -u root sshd : will only list the processes called sshd AND owned by root pgrep -u root,daemon : will list the processes owned by root OR daemon . 4) pidof find the process ID of a running program pidof emacs list the process id for emacs pgrep and pidof is much the same except that grep is more powerful it has more options (check man pages for both) . 5) pkill = kill all processes matching the search text pkill sshd : kill all sshd processes pkill -9 u userlogin : kill a process owned by a particular user . 6) kill = Send a signal to terminate one or more process IDs kill 2345 : terminate process 2345 (to list process id use ps) kill -9 2345 : if kill 2345 doesnt work, use kill -9 2345 to force it . 7) killall = kill all processes by name killall nautilus Unlike the kill command, it is not necessary to first try to find the PID(s) for nautilus. And if there are multiple instances of nautilus running, all will be terminated immediately. killall is similar to pkill

September 26, 2008 Linux Command 10 : su, su -, sudo, wc, cut, diff Posted by linuxlibrary under Uncategorized | Tags: cut, diff, linux command, su, sudo, wc | Leave a Comment 1) su = become super user or another user Examples: I already login as a normal user. To switch to root I can type su <enter> : it will ask for root password then will log in to root account but maintaining the user environment su root <enter> : same as above su <enter> : after entering the root password it will log in to root account with root environment (processing all login scripts) su david <enter> : login to davids account with davids environment The difference between su and su is one will maintain the user environment while the other will use the new user environment . 2) sudo = execute a command as another user, as specified in the sudoers file. a) by default, sudo requires that users authenticate themselves with a password (not root password)

b) sudo determines who is an authorized user by consulting the file /etc/sudoers. the login access have to be created by root user in this file c) basically sudo is used to give access to superusers to do administrative job without them login using root account, so monitoring of each task done by many administrators can be recorded properly Examples: sudo more /etc/sudoers : in order to view a content where the user has no access, he can use sudo sudo shutdown -h now : to shutdown a machine using sudo is by just adding the word sudo in front of any command that requires root/superuser privileges . 3) wc = wc displays a count of lines, words, and characters in a file Examples: wc resignationletter.txt output is : 10 52 121 resignationletter.txt 10 = lines, 52 = words, 121 = characters wc -w resignationletter.txt the command above is to get only the word count wc -c filename : to get the character count wc -l filename : to get the number of lines in the document . 4) cut = takes a vertical slice of a file, printing only the specified columns or fields Eg 1 : For Findind List of users available on your linux machine ( see the previous post) cut -d : -f 1 /etc/passwd /etc/passwd is the file about user information , the general format of this file is username:password:userid:groupid:userdirectory:usershell or antony:x:103:105:/home/antony:/bin/sh x means password is in /etc/shadow field now i want ot retrieve the all username and their userid from that file the command is cut -d : -f 1 3 /etc/passwd cut command name -d delimiter (:) -f field numbers seperated by space (1 -username , 3 userid) Eg 2: the same like we can retrieve the groups details from /etc/groups cut -d : -f 1 /etc/groups taken from http://linuxforadmin.blogspot.com/2007/08/cut-command.html . 5) diff = displays two files and prints the lines that are different Examples: diff filenew.txt fileold.txt : use to compare the different between the two files. more examples at http://lowfatlinux.com/linux-compare-files-diff.html September 25, 2008

Linux Command 9 chown, chgrp, chmod, umask Posted by linuxlibrary under Uncategorized | Tags: chgrp, chmod, chown, linux command, umask | Leave a Comment 1) chown : change file owner and group To check the ownership of a file or directory use ls -l Usage: chown [-Rcfv] newowner filenames/directory. Take note only root can change the ownership. Example: chown linda file.txt This will cause file.txt to now be owned by linda. chown -R abu:sales /home/account/ This is going to make all files inside /home/account/ and its subdirectories to belong to abu and to be associated with the group sales. -R means include all subdirectories . 2) chgrp : change group ownership Usage : chgrp [-Rcfv] groupname foo.txt Example: chgrp marketing file.txt - to change the group specified to a certain document chgrp oracle /usr/database to change the group specified to a certain directory chgrp -R marketing /sales/2008 to change the group specified to a certain directory recursively . 3) chmod : to change the permissions of a file or directory. Use ls -l to see the permission settings. Below is how the permission is assigned. rwx rwx rwx = 111 111 111 rw- rw- rw- = 110 110 110 rwx --- --- = 111 000 000 and so on... rwx = 111 in binary = 7 rw- = 110 in binary = 6 r-x = 101 in binary = 5 r-- = 100 in binary = 4 For example, if we wanted to set some_file to have read and write permission for the owner, but wanted to keep the file private from others, we would: chmod 600 some_file Here is a table of numbers that covers all the common settings. The ones beginning with 7 are used with programs (since they enable execution) and the rest are for other kinds of files. Value 777 755 700 Meaning (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting. (rwxr-xr-x) The files owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users. (rwx) The files owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from

others. 666 644 600 (rw-rw-rw-) All users may read and write the file. (rw-rr) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change. (rw-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Here are some useful settings for directories: Value 777 Meaning (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting. (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users. (rwx) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.

755

700

taken from http://www.linuxcommand.org/lts0070.php chmod Shortcuts Who The who is a list of letters that specifies whom youre going to be giving permissions to. These may be specified in any order. u g o a . Permissions Of course, the permissions are the same letters that you see in the directory listing: r Permission to read the file. w Permission to write (or delete) the file. x Permission to execute the file, or, in the case of a directory, search it. Lets say we have these files: -rwxrwxrwx joe acctg wordmatic -r--r--r-- joe acctg calcmatic Wed like to remove write permission for the group and others on wordmatic, and add write and execute permission for all users on calcmatic. Rather than try to figure out what the new permissions are and do these commands: chmod go=rx wordmatic chmod a=rwx calcmatic The chmod command literally lets us add and subtract permissions from an existing set by using + or instead of =. Thus, we can take away the first files write permission for the group and others with this command: chmod go-w wordmatic The user who owns the file (this means you.) The group the file belongs to. The other users all of the above (an abbreviation for ugo)

and we can add write and execute permission to the second file for all users with: chmod a+wx calcmatic Copying Permissions As one other shortcut, its possible to tell chmod give users of one class the same permissions that some other class has. Lets say we have these files: d------rwx joe acctg sales -rw-r--r-- joe acctg info.dat The other users have full permissions on the sales directory. Wed like to say the user and group should be assigned (=) the permissions belonging to others. That translates to: chmod ug=o Similarly, to make info.dat readable and writable to the group, we can say: chmod g=u info.dat (you can read this as the group is assigned (=) the permissions currently held by the user.) You may also use + and to add and subtract the permissions that currently belong to a different class of user. You cant mix the standard permissions (r, w, and x) with the coyping shortcuts. chmod will protest if you give it something like this: chmod g=wu info.dat Taken from http://catcode.com/teachmod/chmod_cmd.html . 4) umask = set file creation mask The UMASK is the default permission setting that is applied to your files and directories when they are created. After files and directories are created, the chmod command can be used to change the permissions to allow or disallow access as before. The UMASK is set when you login to a UNIX machine. It is, however, possible to change your UMASK and put the UMASK in your login files so that your default permissions are always set for files when you create them. Just like chmod, a umask works on a number. However, instead of the numbers being ADDED like chmod, with a umask the numbers are SUBTRACTED from 7. So from chmod Read 4 Write 2 Execute 1 If a user wants all directories to be created with rwxr-xr-x, that is Owner == Read, Write, Execute == 7 4 2 1 == 0 Group == Read, Execute == 7 4 1 == 2 Others == Read, Execute == 7 4 1 == 2 Then the umask would be 022 There is one important difference with the UMASK and files and directories the execute part will be set on directories, but they have to be manually changed on files after the file has been created. The read and write parts remain the same. You can change your default UMASK using the command umask. For example, the command: umask 022 Will change your umask to the permissions stated above.

To make your new umask be the default for your next login, you will have to edit your .login file and place the umask command down the bottom of that file. The next time you login to your UNIX system, your default umask will be set to that which you have specified in your .login file. For redhat, to change permanently modify .bashrc and include umask nnn in one of the lines. September 20, 2008 Linux Command 8 find, locate, whereis, sort, grep Posted by linuxlibrary under Uncategorized | Tags: find, grep, linux command, locate, sort, whereis | Leave a Comment 1) find = finds one or more files assuming that you know their approximate filenames Examples: find -name mypage.htm In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory. find / -name mypage.htm In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root. find -name file* In the above example the system would search for any file beginning with file in the current directory and any subdirectory. find -name * -size +1000k In the above example the system would search for any file that is larger then 1000k. find /usr -name *stat Find every file under the directory /usr ending in .stat. find / -mtime -2 -print Search the system for files that were modified within the last two days (good candidates for backing up) More examples: http://www.oracle.com/technology/pub/articles/calish-find.html . 2) locate = find files by name Searches are conducted against a database of system contents that is updated periodically. To update the database, use the updatedb command. locate "*.png" to display all files on the system that have the .png filename extension locate "*.png" -q to suppress error messages, such as those that might be returned in the event that the user does not have permission to access designated files or directories locate -n 15 "*.html" display only 15 results in a search for files that have an .html extension: locate "*.html" | less presents only one screenful of output at a time locate -i "*.HtmL" The -i option performs a case-insensitive search. That is, it will return any results that match the arguments regardless of whether individual letters are lower case or upper case. . 3) whereis = the whereis command is used to locate the binary, the source code and the online manual page for any specified program. Take note it is not for searching your files.

Example: whereis locate locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz whereis -b locate (search only binaries) locate: /usr/bin/locate . 4) sort = sort lines of text files sort can be used in many ways, below are some simple examples a) example 1 assume i have 1 text file with name fruits containing below orange lemon and another text file veggy with contents below papaya cucumber sort fruits veggy : it will produce output in alphabetical order as below cucumber lemon orange papaya sort fruits veggy > fruitveggy : this command will save into a file fruitveggy b) example 2 i can create a text file that is sorted in real time, for example, by typing sort > color it will put me into data entry mode, i can keep entering data for example blue, green, yellow each followed by <enter> command. once im done, pressing Ctrl-D keep me back at command prompt. now if i check the text file color i can see alll my input is there already sort out c) example 3 i have a data file data.txt as below: 24 John 45 Sharon 98 Robert i want to sort it on second field (name by alphabetical order), i can use this command sort -d -k 2 data.txt , the output will be 24 John 98 Robert 45 Sharon Explanation: The -d switch stands for dictionary sort and ensures that sorting takes place alphabetically as a dictionary would do it. The -k switch stands for key and with the 2 tells sort to sort on the second field in the file, that is the names. . 5) grep = finds text within a file grep tutorial *.htm = search all .htm files in the current directory for the text tutorial grep -i love history.txt = print all lines containing love (ignoring uppercase and lowercase) in history.txt

grep -ic love me history.txt = To print just the number of lines containing the word love me grep -r tutorial * = -r is to search not only in the current directory but recursively in all the sub directories, the symbol * means to search all files ls | grep readme = this command is to print all files that has the phrase readme in the filename. take note it is not the text inside the document but the name of the document ls -l | grep rwxrwxrwx = to find all filesystem objects in the current directory whose permissions have been set so that any user can read, write and execute them September 19, 2008 Linux Command 7 more, less, head, tail, cat Posted by linuxlibrary under Uncategorized | Tags: cat, head, less, linux command, more, tail | Leave a Comment 1) more = to view a text file one page at a time, press spacebar to go to the next page more filename : show the document one page at a time more -num filename : show the document page few lines as specified bu (-num) example : more -10 filename will show 10 lines for every page . 2) less = is much the same as more command except: a) You can navigate the page up/down using the less command and not possible in more command. b) You can search a string in less command. (use /keywordto search) c) more was fairly limited, and additional development on more had stopped d) it uses same functions as vi editor the usage : less filename . 3) head = displays the first ten lines of a file, unless otherwise stated. Examples head myfile.txt Would display the first ten lines of myfile.txt. head -15 myfile.txt Would display the first fifteen lines of myfile.txt. . 4) tail = display the last part of the file usage : tail filename tail -n filename : display the last n lines of the file . 5) cat = can be used to join multiple files together and print the result on screen (it will not show page by page) usage: cat 01.txt to displat the contents of file 01.txt cat 01.txt 02.txt to display the contents of both files cat file1.txt file2.txt > file3.txt Reads file1.txt and file2.txt and combines those files to make cat note5 >> notes attach note5 to notes cat >> file1 add additional data in file1

September 18, 2008 Linux Command 6 man, apropos, info, whatis, help, file Posted by linuxlibrary under Uncategorized | Tags: apropos, file, help, info, linux basic command, linux command, man, whatis | Leave a Comment 1) man = manual provides in depth information about the requested command man mkdir gives the details how to use mkdir command together with the syntax man -k reboot quickly search for manuals containing reboot within them man -h keyword - Print a one-line help message and exit. . 2) apropos = Its useful if you know only a part of the name or description of a command. Say for example, you want to add a user, but you do not know the specific command, you can try apropos user. It will list out the database of commands that related to user. . 3) info = readable online documentation. for example, info useradd will give a detail explanation of this syntax . 4) whatis = it search the database for the keyword, and print it in a single line. it is the same as apropos except you must type the correct keyword else it will not show any result Example: whatis finger . 5) help = display a brief help on a command (it doesnt contain all commands) usage = keyword help Ecample: reboot help Many of the syntax are not available for example useradd help will not give any result . 6) file = determine file type Examples: file * : will list all files in the directory with the file type information file report2007.txt : report2007.txt: ASCII text September 17, 2008 Linux Command 5 mv, cp, rm, mkdir, rmdir Posted by linuxlibrary under Uncategorized | Tags: cp, linux command, mkdir, mv, rm, rmdir | Leave a Comment 1) mv = renames a file or moves it from one directory to another directory Syntax mv [-f] [-i] oldname newname (to rename) mv [-f] [-i] filename newdirectory -f mv will move the file(s) without prompting even if it is writing over an existing target. Note that

-i oldname newname filename Examples

this is the default if the standard input is not a terminal. Prompts before overwriting another file. The oldname of the file renaming. The newname of the file renaming. The name of the file you want to move directory The directory of were you want the file to go.

mv myfile.txt newdirectory/ moves the file myfile.txt to the directory newdirectory. mv myfile.txt ../ moves the file myfile.txt back one directory (if available). . 2) cp = copies files from one location to another Examples cp file1.txt newdir Copies the file1.txt in the current directory to the newdir directory. cp /home/public_html/mylog.txt /home/public_html/backup/mylog.bak Copies the mylog.txt file in the public_html directory into the public_html/backup directory as mylog.bak. The files are identical however have different names. cp *.txt newdir Copy all files ending in .txt into the newdir directory. cp -r /home/hope/files/* /home/hope/backup Copies all the files, directories, and subdirectories in the files directory into the backup directory. . 3) rm : deletes a file without confirmation (by default). rm myfile.txt Remove the file myfile.txt without prompting the user. rm -r directory Remove a directory, even if files existed in that directory. It will prompt for every single file rm -rf directory Remove a directory, even if files existed in that directory.It will not ask for confirmation for each file. To remove a file whose name starts with a `-, for example `-foo, use one of these commands: rm -foo rm ./-foo . 4) mkdir = to create a new directory mkdir filename . 5) rmdir = deletes a directory rmdir mydir removes the directory mydir (it wont work if files existed in the directory) rm -r directory would remove a directory, even if files existed in that directory. there is no -r option for rmdir, therefore to remove a directory with files inside can use rm -r or rm-rf rmdir -p dir3/dir4/dir5 - remove dir5, dir4 and dir3 if dir5 were empty, dir4 only contained dir5 and dir3 only contained dir4 (which, in turn, contained dir5): September 17, 2008

Linux Command 4 : logout, finger, alias, ln, touch Posted by linuxlibrary under Uncategorized | Tags: alias, finger, linux command, ln, logout, touch | [4] Comments 1) logout = exit a login shell A login shell, is your topmost shell, and is started when you log in. When you terminate a login shell (via the commands `exit, `logout, or the end of file [^D]), you are logged out completely. A `sub-shell is a shell created after login, either by loading a new shell or opening a window with a graphics interface. A sub-shell usually will not accept the command `logout to terminate, you must use `exit or ^D. When you terminate a sub-shell, you are returned to the process or shell that created it. . 2) finger = user information lookup program usage : finger [-b] [-f] [-h] [-i] [-l] [-m] [-p] [-q] [-s] [-w] [username] example : finger -q username -b -f -h -i -l -m -p -q -s -w . Suppress printing the users home directory and shell in a long format printout. Suppress printing the header that is normally printed in a non-long format printout. Suppress printing of the .project file in a long format printout. Force idle output format, which is similar to short format except that only the login name, terminal, login time, and idle time are printed. Force long output format. Match arguments only on user name (not first or last name). Suppress printing of the .plan file in a long format printout. Force quick output format, which is similar to short format except that only the login name, terminal, and login time are printed. Force short output format. Suppress printing the full name in a short format printout.

3) alias = create a shortcut to a command. The format is alias name=command. Example: alias home=cd /home/dave/public_html just by typing home will put you in /home/dave/public_html directory To see the list of alias already set type alias . 4) ln = make links between files ln command has two types a) hard link = to assign a keyword to link to a file deep in directory, so easier to open it. Example: I am always working on this file /home/amrun/projects/bubblegum/secret.txt. To make it easier to access it everyday i create a hard link : ln /home/amrun/projects/bubblegum/secret.txt bbgumformula Now i can just open bbgumformula it will directly open the file secret.txt b) symbolic link = to create a link to a directory, must use symlink. Symlinks are also required when linking to a file on a different disk partition or on a network. ln -s /dev/fd0 A: ln -s /etc/httpd/conf web The first example allows you to access the floppy drive as drive A, just like in DOS, and the second creates a directory entry called web that can be used instead of /etc/httpd/conf. . 5) touch = changes the date/time stamp of the file filename to the current time. Creates an empty file if the file does not exist. EXAMPLE

% touch analysis_data.xls it changes the timestamp of file analysis_data.xls to the current time. There are three date/time values associated with every file on an ext2 filesystem: - the time of last access to the file (atime) - the time of last modification to the file (mtime) - the time of last change to the files inode (ctime). Touch will change the first two to the value specified, and the last one always to the current system time. OPTIONS -a, time=atime, time=access, time=use Change the access time only. -c, no-create Do not create files that do not exist. -d, date time Use time (which can be in various common formats) instead of the current time. It can contain month names, timezones, `am and `pm, etc. -m, time=mtime, time=modify Change the modification time only. -r, file reference-file Use the times of reference-file instead of the current time. -t MMDDhhmm[[CC]YY][.ss] Use the argument (months, days, hours, minutes, optional century and years, optional seconds) instead of the current time. For details, some good example: http://www.linfo.org/touch.html Next Page

Search for:

Search

October 2011 M T W T Sep 3 10 17 24 31 4 11 18 25 5 12 19 26 6 13 20 27 F S 1 8 15 22 29 S 2 9 16 23 30

7 14 21 28

Recent Posts

Linux Command 14 = ifconfig, ifup, ifdown, ping, traceroute, host, dig Linux Command 13 jobs, bg, fg, nice, renice, at, top Linux Command 12 ps, ptree, pgrep, pidof, pkill, kill, killall Linux Command 11 useradd, userdel, usermod, groupadd, last, lastb

Linux Keyboard Shortcuts for Command Line : tab key, ctrl+R, !string and !num, tilde (`),
command editing tricks

Linux Command 10 : su, su -, sudo, wc, cut, diff Linux Command 9 chown, chgrp, chmod, umask Linux Command 8 find, locate, whereis, sort, grep Linux Filesystems Filesystem hierachy standard Linux Filesystems type of filesysystems How to change font and background color in shell terminal Linux Command 7 more, less, head, tail, cat Linux Command 6 man, apropos, info, whatis, help, file Linux Command 5 mv, cp, rm, mkdir, rmdir Linux Command 4 : logout, finger, alias, ln, touch
Archives

September 2008
Blogroll

WordPress.com WordPress.org
Blog at WordPress.com. Theme: Connections by www.vanillamist.com. Follow Follow Linux from beginning Get every new post delivered to your Inbox. Enter email address

Sign me up!
Powered by WordPress.com

Você também pode gostar