Linux command line

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.
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,178评论 0 10
  • 最痛苦的是,消失的东西,它就永远的不见了,永远都不会再回来,却偏还要留下一根细而尖的针,一直插在你心头,一直拔不去...
    北渡姑娘阅读 2,732评论 0 1
  • 后来我遇见的很多人身上,都有你的影子。 故事的开头,有一个女生嚷嚷着拽着满脑子天真幻想的男孩说,你得送我回家。 就...
    G6_程序员阅读 2,425评论 0 1
  • 开发中我们正面临的问题... API发展的当下与趋势标准化API越来越多跨平台调用需求越来越普及开放平台普及化 A...
    特里斯谭阅读 10,217评论 3 62

友情链接更多精彩内容