Skip to content

MiKoronjoo/os-lab-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 

Repository files navigation

OS LAB cheat sheet

Table of Contents

Section Topic
Lesson 1 basic terminal commands
Lesson 2 file permissions & groups
Lesson 3 ps command
Lesson 4 kill & ping
Lesson 5 foreground and background
Research 1 NI vs PRI & daemon
Lesson 6 nice and renice

Lesson 1

  1. ls - list directory contents
    ls [OPTION]... [FILE]...
    List information about the FILEs (the current directory by default).
    1. ls: displays files in a bare format
    $ ls
    README.md
    1. ls -l: long format, displaying Unix file types, permissions, number of hard links, owner, group, size, last-modified date and filename
    $ ls -l
    total 0
    -rw-r--r-- 1 hassan hassan 0 Aug   13 23:55 README.md
  2. pwd - print name of current/working directory
    pwd [OPTION]...
    Print the full filename of the current working directory.
    $ pwd
    /home/hassan/os-lab-cheatsheet
  3. cd - change directory
    cd DIRECTORY...
    Change the current working directory to given directory (home directory by default).
  4. mkdir - make directories
    mkdir [OPTION]... DIRECTORY...
    Create the DIRECTORY(ies), if they do not already exist.
    $ mkdir test
    $ ls
    README.md  test
  5. rm - remove files or directories
    rm [OPTION]... [FILE]...
    rm removes each specified file. By default, it does not remove directories.
    1. rm -r: remove directories and their contents recursively
    2. rm -f: ignore nonexistent files and arguments, never prompt
    3. rm -rf: remove directories and their contents recursively, by force
  6. touch - change file timestamps
    touch [OPTION]... FILE...
    1. touch: a FILE argument that does not exist is created empty
    $ touch file.txt
  7. cp - copy files and directories
    cp [OPTION]... [-T] SOURCE DEST
    Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
    $ cp README.md test
Note:
  1. You should use sudo before your commad when you want to run the command under the root permission. Also switch to root user with sudo -i. Use exit or CTRL+D to exit from root shell.
  2. In terminal, . means current working directory and .. means parent of current directory.
    $ pwd
    /home/hassan/os-lab-cheatsheet
    $ cd ../..
    $ pwd
    /home

Lesson 2

  1. File permissions in Linux/Unix:
    The first set of three permissions, after the place for d, applies to the owner of the file
    The second set of three permissions applies to the all users who are members of the group of the file
    The third set of three permissions applies to others
    alt tag

    1. Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.
    2. Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory.
    3. Execute: In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.
  2. Number of each permission:

    Number Permission Type Symbol
    0 No Permission ---
    1 Execute --x
    2 Write -w-
    3 Execute + Write -wx
    4 Read r--
    5 Read + Execute r-x
    6 Read + Write rw-
    7 Read + Write + Execute rwx
  3. chmod - change file mode bits
    chmod [OPTION]... MODE[,MODE]... FILE...
    chmod changes the file mode bits of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

    $ chmod 755 README.md

    alt tag

  4. groupmod - modify a group definition on the system
    groupmod [options] GROUP
    The groupmod command modifies the definition of the specified GROUP by modifying the appropriate entry in the group database.

    $ groupadd new_group
  5. groups - print the groups a user is in
    groups [OPTION]... [USERNAME]...
    Print group memberships for each USERNAME or, if no USERNAME is specified, for the current process (which may differ if the groups database has changed).

    $ groups hassan
    hassan : hassan adm cdrom sudo dip plugdev lpadmin sambashare
  6. useradd - create a new user or update default new user information
    useradd [options] LOGIN useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.

  7. adduser, addgroup - add a user or group to the system
    adduser [options] user group
    adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs.

    $ adduser new_user
  8. usermod - modify a user account
    usermod [options] LOGIN
    The usermod command modifies the system account files to reflect the changes that are specified on the command line.

    1. usermod -G GROUP1[,GROUP2,...[,GROUPN]]]: new list of supplementary GROUPS
    2. usermod -a USER: add the USER to the supplementary group(s). Use only with the -G option
    $ usermod -G new_group -a new_user

Lesson 3

  1. ps - report a snapshot of the current processes.
    ps [options]
    ps displays information about a selection of the active processes.
    $ ps
      PID TTY          TIME CMD
    18920 pts/3    00:00:00 zsh
    18968 pts/3    00:00:00 ps
    1. ps -l: long format
    F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
    0 S  1000 19749 19738  0  80   0 -  6679 sigsus pts/2    00:00:00 zsh
    4 R  1000 19962 19749  0  80   0 -  5709 -      pts/2    00:00:00 ps
    1. ps -f: full-format, including command lines
    $ ps -f
    UID        PID  PPID  C STIME TTY          TIME CMD
    hassan   18920 18534  7 16:04 pts/3    00:00:00 zsh
    hassan   18956 18920  0 16:04 pts/3    00:00:00 ps -f
    1. ps -t: all processes on this terminal
    $ ps -t
      PID TTY      STAT   TIME COMMAND
    18920 pts/3    Ss     0:00 zsh
    19193 pts/3    R+     0:00 ps -t
    1. ps -r: only running processes
    $ ps -r
      PID TTY      STAT   TIME COMMAND
    19245 pts/3    R+     0:00 ps -r
    1. ps -e: all processes
    2. ps aux:
      a = show processes for all users
      u = display the process's user/owner
      x = also show processes not attached to a terminal
      use grep for searching from command output
    $ ps aux | grep zoom
    hassan   13232 33.9  3.9 5151328 484560 tty2   SLl+ 14:41  43:40 /opt/zoom/zoom
    hassan   22290  0.0  0.0  20476  2900 pts/3    S+   16:50   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn zoom

Lesson 4

  1. kill - send a signal to a process
    kill [options] [...]
    The default signal for kill is TERM. Use -l or -L to list available signals.
    $ kill -l
    HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
    1. kill PID: terminate a process with PID
    $ kill 13232
    1. killall PNAME: terminate all processes with PNAME
    $ killall zoom
  2. xkill - kill a client by its X resource
    xkill is a utility used for force-quitting GUI apps. It is handy when some app isn't responding or is causing your system to work abnormally.
  3. pstree - display a tree of processes
    pstree shows running processes as a tree.
  4. ping - send ICMP ECHO_REQUEST to network hosts
    ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.
    $ ping api.telegram.org
    PING api.telegram.org (149.154.167.220) 56(84) bytes of data.
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=1 ttl=50 time=12.9 ms
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=2 ttl=50 time=13.6 ms
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=3 ttl=50 time=13.1 ms
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=4 ttl=50 time=12.10 ms
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=5 ttl=50 time=13.1 ms
    64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=6 ttl=50 time=12.10 ms

Lesson 5

  1. Foreground and Background Processes:
    Foreground processes refer to applications you are running that you are currently interacting with, and which applies equally to graphical user interfaces as it does to the command line. Background processes refer to applications that are running but not being interacted with by the user.
  2. nano - Nano's ANOther editor, an enhanced free Pico clone
    nano is a small and friendly editor.
    1. nano FILE: open FILE with nano (create the FILE if is not exists)
    $ nano script.sh
  3. cat - concatenate files and print on the standard output
    cat [OPTION]... [FILE]...
    Concatenate FILE(s) to standard output.
    $ cat script.sh
    ping google.com > res.out
  4. jobs - display the status of jobs in the current shell
    $ jobs
    [1]  + suspended  ./script.sh
  5. bg - move jobs to the background
    1. bg %jobID
    $ bg %1
    [1]  + 28975 continued  ./script.sh
  6. fg - move jobs to the foreground
    1. fg %jobID
    $ fg %1
    [1]  + 28975 running    ./script.sh

    Note:

    1. You can suspend a job with CTRL+Z
    2. You can end a job with CTRL+C

Research 1

  • Nice Value and Priority
    PRI is the priority level. The lower the PRI, the higher the priority of the process will be.
    PRI is calculated as follows:
    • for normal processes: PRI = 20 + NI (NI is nice and ranges from -20 to 19)
    • for real time processes: PRI = - 1 - real_time_priority (real_time_priority ranges from 1 to 99)
      The nice value is a "global" mechanism, whereas priority is relevant for the task switcher right now.
  • Daemon Process
    A daemon process is a background process that is not under the direct control of the user. This process is usually started when the system is bootstrapped and it terminated with the system shut down.
    In Unix, the names of daemons conventionally end with the letter d, for clarification that the process is in fact a daemon, and for differentiation between a daemon and a normal program.

Lesson 6

  1. top - display Linux processes
    The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.
    Use q or CTRL+C to exit from top.

  2. nice - run a program with modified scheduling priority
    nice [OPTION] [COMMAND [ARG]...]

    1. nice -n: add integer N to the niceness (default 10)
    $ nice -n 15 nautilus

    Note: You should have root permission for negative nice values.

    $ sudo nice -n -8 nautilus
  3. renice - alter priority of running processes
    renice [-n] priority [-g|-p|-u] identifier...
    renice alters the scheduling priority of one or more running processes. The first argument is the priority value to be used. The other arguments are interpreted as process IDs (by default), process group IDs, user IDs, or user names.

    $ renice 2 14862
    14862 (process ID) old priority 0, new priority 2

About

OS Lab cheat sheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published