Linux Intro
Linux Intro
Linux Intro
1. vim
2. whoami
3. adduser/useradd
4. passwd
5. /etc/passwd
6. /etc/shadow
7. addgroup
8. /etc/group
9. delgroup
10. usermod
11. Super user privileges
12. su/sudo
13. /etc/sudores
14. ls/dir
15. mkdir
16. touch
17. cat
18. find
19. cp
20. mv
21. Introduction to File permissions
22. id
23. stat
24. chmod
25. chown
vim
1 of 8
Cut into buffer: "add
Paste from buffer: "ap
Undo
Undo: u
Undo to a given step: :undo <number>
Undo backward: :earlier <number>f
Redo forward: :later <number>f
Find and replace
Line: :%s/<find>/<replace>/
Range: :45,50 s/<find>/<replace>/g
Full document: :%s/<find>/<replace>/g
Split/Tabs
Split: :split <file> or :vsplit <file>
Change active split: <Ctrl>w+<Ctrl>-w
Tab: :tabe <file>
Check spell
Start: :set spell
Stop: :set spell!
Corrections: z=
More configuration (with ~/.vimrc)
syntax on
set tabstop=3
Code completion
Start: :autocmd FileType php set omnifunc=phpcomplete#CompletePHP
Help (Really useful)
Start: :help or <F1>
Jump to subject: <Ctrl>]
Jump back: <Ctrl>o
whoami
Print the user name associated with the current effective user
whoami
adduser/useradd
passwd
2 of 8
Display this help message and exit
password -h
Change password only if expired
password -k
Set password inactive after expiration
password -i
/etc/passwd
/etc/shadow
addgroup
/etc/group
3 of 8
1. group_name: It is the name of group. If you run ls -l command, you will see this name printed in the group
field.
2. Password: Generally password is not used, hence it is empty/blank. It can store encrypted password. This
is useful to implement privileged groups.
3. Group ID (GID): Each user must be assigned a group ID. You can see this number in your /etc/passwd file.
4. Group List: It is a list of user names of users who are members of the group. The user names, must be
separated by commas.
delgroup
usermod
In Linux and Unix like computer operating systems, root is the conventional name of the user who has all
rights or permissions (to all files and programs) in all modes (single- or multi-user).
The root user can do many things an ordinary user cannot, such as changing the ownership of files and
binding to ports numbered below 1024. The etymology of the term may be that root is the only user
account with permission to modify the root directory of a Unix system.
su/sudo
Change user:
su -l <username>
Change to super user:
su -l
sudo allows a permitted user to execute a command as the superuser or another user, as specified in the
sudoers file.
Run command as super user:
sudo <command>
Use shell with super user privileges:
sudo -i or sudo bash
/etc/sudores
ls/dir
4 of 8
All:
ls -A
Sort:
ls -tr
mkdir
Create directories
Create a directory:
mkdir <dir_name>
Create directory hierarchy:
mkdir -p kkk/lll/{mmm,nnn}
touch
cat
find
Find a files/dirs:
find <dir_name> -iname <file_name_regexp>
Find a files:
find <dir_name> -type f -iname <file_name_regexp>
Find files/dirs modified before 7 days:
find <dir_name> -mtime -7 -iname <file_name_regexp>
Delete what found:
find <dir_name> -mtime -7 -iname <file_name_regexp> -delete
Execute commands on what found:
find <dir_name> -mmin -10 -exec ls -l '{}' \;
5 of 8
cp
Copy file:
cp <source_file> <destination>
Copy directory:
cp -r <source_dir> <destination>
Create hard links instead of copy:
cp -l <source_file> <destination>
See what's copying:
cp -v <source_file> <destination>
mv
Move file:
mv <source_file> <destination>
Rename file:
mv <prev_name> <cur_name>
1 2 3 4 5 6 7 8 9 10
File User Permissions Group Permissions Other Permissions
Type Read Write Execute Read Write Execute Read Write Execute
d r w x r w x r w x
Description of each character
Character 1 is the type of file: - is ordinary, d is directory, l is link.
Characters 2-4 show owner permissions. Character 2 indicates read permission, character 3
indicates write permission, and character 4 indicates execute permission.
Characters 5-7 show group permissions. Character 5=read, 6=write, 7=execute
Characters 8-10 show permissions for all other users. Character 8=read, 9=write, 10=execute
There are 5 possible characters in the permission fields. They are:
1. r = read - This is only found in the read field.
2. w = write - This is only found in the write field.
3. x = execute - This is only found in the execute field.
4. s = setuid - This is only found in the execute field.
5. If there is a "-" in a particular location, there is no permission. This may be found in any field whether
read, write, or execute field.
id
6 of 8
stat
File status:
stat <file_name>
File status formatted output:
stat <file_name> -c <format_string>
File type: %F
Time of last modification: %y
Total size, in bytes: %s
File system status:
stat -f <file_name>
File system status formatted output:
stat -f <file_name> -c <format_string>
File system type: %T
Total data blocks in file system: %b
Total file nodes in file system: %c
Access,Modify,Change
Access Time: This is the time that the file was last accessed, read or written to.
Modify Time: This is the last time the actual contents of the file were last modified.
Change Time: This is the time that the inode information (permissions, name, etc., the metadata, as
it were) was last modified
chmod
Who
u : The user who owns the file (this means “you.†)
g : The group the file belongs to.
o : The other users
a : all of the above (an abbreviation for ugo)
Permissions
r : Permission to read the file.
w : Permission to write the file.
x : Permission to execute the file, or, in the case of a directory, search it.
Change mode to user can write,group can read only:
chmod u+w,g-w <file_name>
Set UID/Set GID (the program will run as the user/group who own file)
chmod u+s <file_name>
chmod g+s <file_name>
Do it by numbers
Binary decimal Permission
000 0 ---
001 1 --x
010 2 -w-
011 3 -wx
100 4 r--
101 5 r-x
7 of 8
110 6 rw-
111 7 rwx
chmod u+w,g-w with numbers:
chmod 644 <file_name>
Set permisions recursively:
chmod 644 -R <dir_name>
chown
8 of 8