美文网首页让前端飞
Linux command line

Linux command line

作者: 不吃猫的鱼_zjh | 来源:发表于2018-07-17 21:49 被阅读1次

Preface

I would be fooling myself if I claim to be proficient in Linux command line. So I took the Linux Command Line video course to enhance my knowledge in the area.

ls: list directory content

Userful Options:

Option Meaning
-l use a long listing format
-a do not ignore entries starting with .
-h with -l, print sizes in human readable format (e.g. 1K 234M 2G)

whatis: displays short manual page descriptions

whatis cp

// output:
cp(1) - copy files

file: find the type of a file

file README.md

// output:
README.md: ASCII text

head: output the first part of file

Userful Options:

Option Meaning
-n specify the number of first lines to print

tail: output the last part of file

Userful Options:

Option Meaning
-n specify the number of last lines to print
-f loop forever, checking for new data at the end of the file(s)

wildcard: a symbol used to replace or represent one or more characters.

wildcard Meaning
* The asterisk in a wildcard matches any character zero or more times
? A question mark matches a single character once
[] match a single character in a range
touch chapters{1,2,3}.txt

// will create chapters1.txt, chapters2.txt and chapters3.txt 

tar: create, maintain, modify, and extract files that are archived in the tar format.

Userful Options:

Option Meaning Example
-c create a new archive. tar -cf archive.tar file1 file2
-f use archive file or device ARCHIVE
-v verbosely list files processed.
-x untar tar archive file tar -cvf archive.tar

gzip: compress

wget: download file over network.

Userful Options:

Option Meaning Example
-O specify output wget -O file http://foo

id: prints real and effective user and group ID

uid=501(michaelzheng) gid=20(staff) groups=20(staff),12(everyone)

groups: show group memberships

groups
//staff everyone 

whoami: prints the effective user

whoami
//michaelzheng

chmod: change the permissions of files or directories

For a file with listing like this:

-rw-r--r--   1 michaelzheng  staff  1983 Jul 17 16:17 README.md

The first char is the type. The 2-4 is the owner permission for reading, writing and execution respectively. 5-6 is for group members and 9-11 is for others. Taking the example above for illustration:

  • -: normal file
  • rw-: owner(i.e. michaelzheng) can read and write
  • r--: groups members can only read
  • r--: others can only read

To change each permission group, we can convert binary representation to octal format.

r w e
4(i.e. 2^2) 2(i.e. 2^1) 1(i.e. 2^0)

Therefore, if I want to grant owner rwx(4 * 1 + 2 * 1 + 1 * 1 = 7), group member rx(4 * 1 + 2 * 0 + 1 * 1 = 5) and others r (4 * 1 + 2 * 0 + 1 * 0 = 4) then i can use

chmod 750 README.md

ps: displays information about a selection of the active processes

jobs: display status of jobs in the current session

fg: run jobs in the foreground

bg: run jobs in the background

df: report file system usage

Useful options:

Option Meaning
-h print sizes in human readable format
du -h

//output: 
Filesystem      Size   Used  Avail Capacity iused      ifree %iused  Mounted on
/dev/disk1     112Gi   97Gi   15Gi    87% 2771640 4292195639    0%   /
devfs          182Ki  182Ki    0Bi   100%     630          0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%       0          0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%       0          0  100%   /home

du: estimate file space usage

Useful options:

Option Meaning
-h print sizes in human readable format
-s display only a total for each argument

Reference

Notice

  • If you want to follow the latest news/articles for the series of reading notes, Please 「Watch」to Subscribe.

相关文章

网友评论

    本文标题:Linux command line

    本文链接:https://www.haomeiwen.com/subject/cuxnpftx.html