Linux-Course

This blog records my Linux learning process.


Commands

ls

1
ls [-a -l -h] [path]

“-a” shows some hidden directories or files.

“-l” shows more information.

“-h” shows the filesize which should be used with “-h”.

cd pwd

1
2
3
cd ./[path]  #workdir
cd .. #predir
cd ~ #homedir

“cd” change directory
“pwd” print work directory

mkdir

1
mkdir [-p] path

Make directory
“-p” can create directory-chain

touch

1
2
3
touch filename   #create file
cat path #show file
more path #show file with pages

cp mv rm

copy move remove

1
2
3
cp [-r] copied copy   #"-r" copy dir
mv moved path/
rm [-r -f] para1 para2 ... paraN #"-r" remove dir "-f" force

“ refers to wildcard
e.g.:”test
“ can represent test1 test2 test3

which find

1
2
3
which command
find startpath -name "filename"
find startpath -size +|-n[kMG] #"-10k" <10kb "+100M" >100Mb

grep wc Pipeline|

global regular expression print, Word count

1
2
3
4
grep [-n] "keyword" path  #"-n" show line number
wc [-c -m -l -w] #"-c"bytesum "-m"charactersum
#"-l"linesum "-w"wordsum
cat filename | grep "keyword"

“left | right” left output is the input of right.

echo `` > >> tail

1
2
3
4
5
6
echo "output word"
echo `command` #same as command > filename #cover the file with the output
command >> filename #add the output to the file
echo 'hello world' >> test.txt
tail [-f -num] path #show tail line of the file
#"-f" can follow change immediately

root

su

switch user

1
2
su [-] [username] #"-" load environment var
exit #back to the pre user

sudo

switch user do
the user who verified can sudo

1
2
sudo command
visudo #verify user

usergroup

1
2
3
4
5
6
7
8
groupadd groupname
groupdel groupname

useradd [-g -d] username #"-g" add to existed group "-d" user home path
userdel [-r] username #"-r" delete user homedir
id [username] #check the usergroup
usermod -aG usergroup username #modify usergroup
getent [passwd group] #check all the usergroup

ls -l description

"ls -l" output
e.g.

1 2 3 4 5 6 7 8 9 10
d rwx rwx r-x 4 xx xx 4096 Feb 2 19:07 Desktop

Field 1- for File, d for Directory, l for Link

Field 2,3,4 Those are permissions that means read, write and execute, and comes in three different fields that belongs to the permission the:

  • second: The owner has over the file
  • third: The group has over the file
  • fourth: Everybody else has over the file

Field 5 This field specifies the number of links or directories inside this directory.

Field 6 The user that owns the file, or directory.

Field 7 The group that file belongs to, and any user in that group will have the permissions given in the third field over that file.

Field 8 The size in bytes, you may modify this by using the -h option together with -l this will have the output in k,M,G for a better understanding.


Linux-Course
http://xxblog.net/Linux/Linux-Course/
Author
XX
Posted on
February 1, 2023
Updated on
March 24, 2023
Licensed under