Advertisement
anshulpandey222

Linux Commands

Feb 21st, 2019
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.95 KB | None | 0 0
  1. Important Linux Commands :
  2.  
  3. This section gives insight into the most important commands of your SuSE Linux system. Along with the individual commands, parameters are listed and, where appropriate, a typical sample application is introduced. To learn more about the various commands, it is usually possible to get additional information with the man program followed by the name of the command, for example, man ls.
  4.  
  5. In these manual pages, move up and down with PgUp and PgDn and move between the beginning and the end of a document with Home and End. End this viewing mode by pressing Q. Learn more about the man command itself with man.
  6.  
  7. There are many more commands than listed in this chapter. For information about other commands or more detailed information, we recommend the O'Reilly publication Linux in a Nutshell. In the following overview, the individual command elements are written in different typefaces.
  8.  
  9.  
  10. Further details, like file names, which must be passed to a command for correct functioning, are written in the Courier font.
  11.  
  12. Specifications or parameters that are not required are placed in [brackets].
  13.  
  14. Adjust possible specifications to your needs. It makes no sense to write ls file(s), if no file named file(s) actually exists. You can usually combine several parameters, for example, by writing ls -la instead of ls -l -a.
  15.  
  16. File Commands
  17. File Administration
  18. ls [option(s)] [file(s)]
  19. If you run ls without any additional parameters, the program will list the contents of the current directory in short form.
  20.  
  21. -l
  22. detailed list
  23.  
  24. -a
  25. displays hidden files
  26.  
  27. cp [option(s)] sourcefile targetfile
  28. Copies sourcefile to targetfile.
  29.  
  30. -i
  31. Waits for confirmation, if necessary, before an existing targetfile is overwritten
  32.  
  33. -r
  34. Copies recursively (includes subdirectories)
  35.  
  36. mv [option(s)] sourcefile targetfile
  37. Copies sourcefile to targetfile then deletes the original sourcefile.
  38.  
  39. -b
  40. Creates a backup copy of the sourcefile before moving
  41.  
  42. -i
  43. Waits for confirmation, if necessary, before an existing targetfile is overwritten
  44.  
  45. rm [option(s)] file(s)
  46. Removes the specified files from the file system. Directories are not removed by rm unless the option -r is used.
  47.  
  48. -r
  49. Deletes any existing subdirectories
  50.  
  51. -i
  52. Waits for confirmation before deleting each file.
  53.  
  54. ln [option(s)] sourcefile targetfile
  55. Creates an internal link from the sourcefile to the targetfile, under a different name. Normally, such a link points directly to the sourcefile on one and the same file system. However, if ln is executed with the -s option, it creates a symbolic link that only points to the directory where the sourcefile is located, thus enabling linking across file systems.
  56.  
  57. -s
  58. Creates a symbolic link
  59.  
  60. cd [options(s)] [directory]
  61. Changes the current directory. cd without any parameters changes to the user's home directory.
  62.  
  63. mkdir [option(s)] directoryname
  64. Creates a new directory.
  65.  
  66. rmdir [option(s)] directoryname
  67. Deletes the specified directory, provided it is already empty.
  68.  
  69. chown [option(s)] username.group file(s)
  70. Transfers the ownership of a file to the user with the specified user name.
  71.  
  72. -R
  73. Changes files and directories in all subdirectories.
  74.  
  75. chgrp [option(s)] groupname file(s)
  76. Transfers the group ownership of a given file to the group with the specified group name. The file owner can only change group ownership if a member of both the existing and the new group.
  77.  
  78. chmod [options] mode file(s)
  79. Changes the access permissions.
  80.  
  81. The mode parameter has three parts: group, access, and access type. group accepts the following characters:
  82.  
  83. u
  84. user
  85.  
  86. g
  87. group
  88.  
  89. o
  90. others
  91.  
  92. For access, access is granted by the + symbol and denied by the - symbol.
  93.  
  94. The access type is controlled by the following options:
  95.  
  96. r
  97. read
  98.  
  99. w
  100. write
  101.  
  102. x
  103. eXecute — executing files or changing to the directory.
  104.  
  105. s
  106. Set uid bit — the application or program is started as if it were started by the owner of the file.
  107.  
  108. gzip [parameters] file(s)
  109. This program compresses the contents of files, using complex mathematical algorithms. Files compressed in this way are given the extension .gz and need to be uncompressed before they can be used. To compress several files or even entire directories, use the tar command.
  110.  
  111. -d
  112. decompresses the packed gzip files so they return to their original size and can be processed normally (like the command gunzip).
  113.  
  114. tar options archive file(s)
  115. The tar puts one file or (usually) several files into an archive. Compression is optional.
  116.  
  117. tar is a quite complex command with a number of options available. The most frequently used options are:
  118.  
  119. -f
  120. Writes the output to a file and not to the screen as is usually the case
  121.  
  122. -c
  123. Creates a new tar archive
  124.  
  125. -r
  126. Adds files to an existing archive
  127.  
  128. -t
  129. Outputs the contents of an archive
  130.  
  131. -u
  132. Adds files, but only if they are newer than the files already contained in the archive
  133.  
  134. -x
  135. Unpacks files from an archive (extraction)
  136.  
  137. -z
  138. Packs the resulting archive with gzip
  139.  
  140. -j
  141. Compresses the resulting archive with bzip2
  142.  
  143. -v
  144. Lists files processed
  145.  
  146. The archive files created by tar end with .tar. If the tar archive was also compressed using gzip, the ending is .tgz or .tar.gz. If it was compressed using bzip2, .tar.bz2.
  147.  
  148. Application examples can be found in Section “Archives and Data Compression”.
  149.  
  150. locate pattern(s)
  151. The locate command can find in which directory a specified file is located. If desired, use wild cards to specify file names. The program is very speedy, as it uses a database specifically created for the purpose (rather than searching through the entire file system). This very fact, however, also results in a major drawback: locate is unable to find any files created after the latest update of its database.
  152.  
  153. The database can be generated by root with updatedb.
  154.  
  155. updatedb [options(s)]
  156. This command performs an update of the database used by locate. To include files in all existing directories, run the program as root. It also makes sense to place it in the background by appending an ampersand (&), so you can immediately continue working on the same command line (updatedb &).
  157.  
  158. find [option(s)]
  159. The find command allows you to search for a file in a given directory. The first argument specifies the directory in which to start the search. The option -name must be followed by a search string, which may also include wild cards. Unlike locate, which uses a database, find scans the actual directory.
  160.  
  161. Commands to Access File Contents
  162. cat [option(s)] file(s)
  163. The cat command displays the contents of a file, printing the entire contents to the screen without interruption.
  164.  
  165. -n
  166. Numbers the output on the left margin
  167.  
  168. less [option(s)] file(s)
  169. This command can be used to browse the contents of the specified file. Scroll half a screen page up or down with PgUp and PgDn or a full screen page down with Space. Jump to the beginning or end of a file using Home and End. Press Q to exit the program.
  170.  
  171. grep [option(s)] searchstring filenames
  172. The grep command finds a specific searchstring in the specified file(s). If the search string is found, the command displays the line in which the searchstring was found along with the file name.
  173.  
  174. -i
  175. Ignores case
  176.  
  177. -l
  178. Only displays the names of the respective files, but not the text lines
  179.  
  180. -n
  181. Additionally displays the numbers of the lines in which it found a hit
  182.  
  183. -l
  184. Only lists the files in which searchstring does not occur
  185.  
  186. diff [option(s)] file1 file2
  187. The diff command compares the contents of any two files. The output produced by the program lists all lines that do not match.
  188.  
  189. This is frequently used by programmers who need only send their program alterations and not the entire source code.
  190.  
  191. -q
  192. Only reports whether the two given files differ
  193.  
  194. File Systems
  195. mount [option(s)] [<device>] mountpoint
  196. This command can be used to mount any data media, such as hard disks, CD-ROM drives, and other drives, to a directory of the Linux file system.
  197.  
  198. -r
  199. mount read-only
  200.  
  201. -t filesystem
  202. Specifies the file system. The most common are ext2 for Linux hard disks, msdos for MS-DOS media, vfat for the Windows file system, and iso9660 for CDs.
  203.  
  204. For hard disks not defined in the file /etc/fstab, the device type must also be specified. In this case, only root can mount. If the file system should also be mounted by other users, enter the option user in the appropriate line in the /etc/fstab file (separated by commas) and save this change. Further information is available in mount.
  205.  
  206. umount [option(s)] mountpoint
  207. This command unmounts a mounted drive from the file system. To prevent data loss, run this command before taking a removable data medium from its drive. Normally, only root is allowed to run the commands mount and umount. To enable other users to run these commands, edit the /etc/fstab file to specify the option user for the respective drive.
  208.  
  209. System Commands
  210. System Information
  211. df [option(s)] [directory]
  212. The df (disk free) command, when used without any options, displays information about the total disk space, the disk space currently in use, and the free space on all the mounted drives. If a directory is specified, the information is limited to the drive on which that directory is located.
  213.  
  214. -H
  215. shows the number of occupied blocks in gigabytes, megabytes, or kilobytes — in human-readable format
  216.  
  217. -t
  218. Type of file system (ext2, nfs, etc.)
  219.  
  220. du [option(s)] [path]
  221. This command, when executed without any parameters, shows the total disk space occupied by files and subdirectories in the current directory.
  222.  
  223. -a
  224. Displays the size of each individual file
  225.  
  226. -h
  227. Output in human-readable form
  228.  
  229. -s
  230. Displays only the calculated total size
  231.  
  232. free [option(s)]
  233. The command free displays information about RAM and swap space usage, showing the total and the used amount in both categories.
  234.  
  235. -b
  236. Output in bytes
  237.  
  238. -k
  239. Output in kilobytes
  240.  
  241. -m
  242. Output in megabytes
  243.  
  244. date [option(s)]
  245. This simple program displays the current system time. If run as root, it can also be used to change the system time. Details about the program are available in date.
  246.  
  247. Processes
  248. top [options(s)]
  249. top provides a quick overview of the currently running processes. Press H to access a page that briefly explains the main options to customize the program.
  250.  
  251. ps [option(s)] [process ID]
  252. If run without any options, this command displays a table of all your own programs or processes — those you started. The options for this command are not preceded by hyphen.
  253.  
  254. aux
  255. Displays a detailed list of all processes, independent of the owner.
  256.  
  257. kill [option(s)] process ID
  258. Unfortunately, sometimes a program cannot be terminated in the normal way. However, in most cases, you should still be able to stop such a runaway program by executing the kill command, specifying the respective process ID (see top and ps).
  259.  
  260. kill sends a TERM signal that instructs the program to shut itself down. If this does not help, the following parameter can be used:
  261.  
  262. -9
  263. Sends a KILL signal instead of a TERM signal, with which the process really is annihilated by the operating system. This brings the specific processes to an end in almost all cases.
  264.  
  265. killall [option(s)] processname
  266. This command is similar to kill, but uses the process name (instead of the process ID) as an argument, causing all processes with that name to be killed.
  267.  
  268. Network
  269. ping [option(s)] host name|IP address
  270. The ping command is the standard tool for testing the basic functionality of TCP/IP networks. It sends a small data packet to the destination host, requesting an immediate reply. If this works, ping displays a message to that effect, which indicates that the network link is basically functioning.
  271.  
  272. -c
  273. number Determines the total number of packages to send and ends after they have been dispatched. By default, there is no limitation set.
  274.  
  275. -f
  276. flood ping: sends as many data packages as possible. A popular means, reserved to root, to test networks.
  277.  
  278. -i
  279. value Specifies the interval between two data packages in seconds. Default: one second
  280.  
  281. nslookup
  282. The Domain Name System resolves domain names to IP addresses. With this tool, send queries to information servers (DNS servers).
  283.  
  284.  
  285. Miscellaneous :
  286.  
  287.  
  288. passwd [option(s)] [username]
  289. Users may change their own passwords at any time using this command. Furthermore, the administrator root can use the command to change the password of any user on the system.
  290.  
  291. su [option(s)] [username]
  292. The su command makes it possible to log in under a different user name from a running session. When using the command without specifying a user name, you will be prompted for the root password. Specify a user name and the corresponding password to use the environment of the respective user. The password is not required from root, as root is authorized to assume the identity of any user.
  293.  
  294. halt [option(s)]
  295. To avoid loss of data, you should always use this program to shut down your system.
  296.  
  297. reboot [option(s)]
  298. Does the same as halt with the difference that the system performs an immediate reboot.
  299.  
  300. clear
  301. This command cleans up the visible area of the console. It has no options.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement