为了账号安全,请及时绑定邮箱和手机立即绑定

Linux command line

标签:
Linux

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


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消