立诚勿怠,格物致知
It's all about connecting the dots

Common Linux Commands

cat:

Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.

  • cat .bashrc: Sends the contents of the “.bashrc” file to the screen.

cd:

Change directory.

  • cd /home: Change the current working directory to /home. The “/” indicates relative to root, and no matter what directory you are in when you execute this command, the directory will be changed to “/home”.
  • cd httpd: Change the current working directory to httpd, relative to the current location which is “/home”. The full path of the new working directory is “/home/httpd”.
  • cd ..: Move to the parent directory of the current directory. This command will make the current working directory “/home”.
  • cd ~: Move to the user’s home directory which is “/home/username”. The ‘~’ indicates the users home directory.

chmod:

Change the permissions of files or directories. (chmod [options] permissions filename)

  • chmod u=rwx,g=rx,o=r myfile: The user can red, write, and execute it; members of your group can read and execute it; and others may only read it.
  • chmod 754 myfile: This is equivalent to the command above. Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0. 4 stands for “read”, 2 stands for “write”, 1 stands for “execute”, and 0 stands for “no permission”. So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
  • chmod -r 754 myfolder: This is equivalent to the command above expect that this command changes files and directories recursively.

chown:

Change the owner and owning group of files. (chown [options] filename)

  • chown chope file.txt: Sets the owner of the file “file.txt” to user chope.
  • chown -R chope /files/work: Recursively grant ownership of the directory /files/work, and all files and subdirectories, to user chope.

clear:

Clear a command line screen/window for a fresh start.

cp:

Copy files.

  • cp myfile yourfile: Copy the files “myfile” to the file “yourfile” in the current working directory. This command will create the file “yourfile” if it doesn’t exist. It will normally overwrite it without warning if it exists.
  • cp -i myfile yourfile: With the “-i” option, if the file “yourfile” exists, you will be prompted before it is overwritten.
  • cp -i /data/myfile .: Copy the file “/data/myfile” to the current working directory and name it “myfile”. Prompt before overwriting the file.
  • cp -dpr srcdir destdir: Copy all files from the directory “srcdir” to the directory “destdir” preserving links (-d option, no dereference and preserve links), file attributes (-p option, preserve mode, ownership, timestamps), and copy recursively (-r option, recursive). With these options, a directory and all its contents can be copied to another directory.

date:

Display or set the system date.

dd:

Dist duplicate. The man page says this command is to “Convert and copy a file”, but although used by more advanced users, it can be a very handy command.

  • dd if=/dev/hdb1 of=/backup/: The “if” means input file, “of” means output file.

df:

Show the amount of disk space used on each mounted file system.

file:

Determine what types of data is within a file. (file [options] filename)

find:

Search for files matching a provided pattern.

  • find *.html: Finds files whose names ends with .html in current working directory.

less:

Similar to the more command, but the user can page up and down through the file.

  • less textfile: The example displays the contents of the file “textfile”.

ln:

Creates a symbolic link to a file.

  • ln -s test symlink: Creates a symbolic link named symlink that points to the file “test”. Typing “ls -i test symlink” will show the two files are different inodes. Typing “ls -l test symlink” will show that symlink points to the file test.

locate:

A fast database driven file locator.

  • locate -u: This command builds the slocate database. It will take several minutes to complete this command. This command must be used before searching for files, however cron runs this command periodically on most systems.
  • locate whereis: Lists all files whose names contain the string “whereis”.
  • locate filename: Search a copy of your filesystem for the specified filename.

logout:

Logs the current user off the system.

ls:

  • ls: List files in the current working directory except those starting with . and only show the file name.
  • ls -al: List all files in the current working directory in long listing format showing permissions, ownership, size, and time and date stamp.

man:

Display the help information for the specified command.

  • man ls: Display the help information for the “ls” command.

mkdir:

Create a new directory. (mkdir [options] directory)

more:

Allow file contents or piped output to be sent to the screen one page at a time.

  • more /etc/profile: Lists the contents of the “/etc/profile” file to the screen one page at a time.
  • ls -al |more: Performs a directory listing of all files and pipes the output of the listing through more. If the directory listing is longer than a page, it will be listed one page at a time.

mv:

Move or rename files. (mv [options] source destination)

  • mv -i myfile yourfile: Move the file from “myfile” to “yourfile”. This effectively changes the names of “myfile” to “yourfile”.
  • mv -i /data/myfile .: Move the file from “myfile” from the directory “/data” to the current working directory.

ps:

Display a snapshot of the currently running processes. (ps [options])

pwd:

Show the name of the current working directory.

rm [options] directory:

Remove (delete) file(s) and/or directories.

  • rm -r mydir

rmdir [options] directory:

Delete empty directories.

shutdown:

Shuts the system down.

  • shutdown -h now: Shuts the system down to halt immediately.
  • shutdown -r now: Shuts the system down immediately and the system reboots.

ssh [options] user@machine:

Remotely log in to another Linux machine, over the network. Leave an ssh session by typing exit.

tail [options] [filename]:

Display the last n lines of a file (the default is 10).

tar [options] filename:

Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz.)

top:

Displays the resources being used on your system. Press q to exit.

touch filename:

Create an empty file with the specified name.

whereis:

Show where the binary, source and manual page files are for a command.

  • whereis ls: Locates binaries and manual pages for the ls command.

who [options]:

Display who is logged on.

Reference:

  • http://www.comptechdoc.org/os/linux/usersguide/linux_ugbasics.html
  • http://www.dummies.com/computers/operating-systems/linux/common-linux-commands/
  • http://stackoverflow.com/questions/160204/how-to-use-ditto-on-os-x-to-work-like-cp-a-on-linux
  • http://www.computerhope.com/unix/uchmod.htm
  • http://www.computerhope.com/unix/uchown.htm
赞(0) 打赏
文章名称:《Common Linux Commands》
文章链接:https://www.orzzone.com/common-linux-commands.html
商业联系:yakima.public@gmail.com

本站大部分文章为原创或编译而来,对于本站版权文章,未经许可不得用于商业目的,非商业性转载请以链接形式标注原文出处。
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力提供更多优质内容!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册