继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Linux command line

LEATH
关注TA
已关注
手记 454
粉丝 93
获赞 467

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:

OptionMeaning
-luse a long listing format
-ado not ignore entries starting with .
-hwith -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:

OptionMeaning
-nspecify the number of first lines to print

tail: output the last part of file

Userful Options:

OptionMeaning
-nspecify the number of last lines to print
-floop forever, checking for new data at the end of the file(s)

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

wildcardMeaning
*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:

OptionMeaningExample
-ccreate a new archive.tar -cf archive.tar file1 file2
-fuse archive file or device ARCHIVE
-vverbosely list files processed.
-xuntar tar archive filetar -cvf archive.tar

gzip: compress

wget: download file over network.

Userful Options:

OptionMeaningExample
-Ospecify outputwget -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.

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

OptionMeaning
-hprint 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:

OptionMeaning
-hprint sizes in human readable format
-sdisplay only a total for each argument



作者:不吃猫的鱼_zjh
链接:https://www.jianshu.com/p/96e7305dc685


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP