Curiosity, learning and homework help
20/10/2021
Sign upLog in
Language: FR | ENG

NEWSLETTER

:

MEMBERS

Come to discuss on the forum!
 FAST and FREE signup. 
😀 Access to discussion forums 😀
Help for HOMEWORKS, support in COMPUTER SCIENCE, help for learning FRENCH and ENGLISH, discussion on your INTERESTS and HOBBIES...

Some useful commands
Here is a list of commands that can be useful to have on hand when working on a UNIX system:

  • See the version of Linux:
  • cat /etc/issue

  • See the name of the current user:
  • whoami

  • See the name of the machine:
  • hostname

  • See who is logged in and what they are doing:
  • w

  • Find a file:
  • find . -name file_name -print

  • Find a directory:
  • find . -name directory_name -d -print

  • Search a string of characters in a file or a directory (by default, the current directory):
  • grep -rni string [file_or_directory]

    r : recursive
    n : display the number of the line in the file
    i : ignore case

  • Display the information of all files:
  • ls -lah

    l : diplay the information
    a : include hidden files and directories
    h : display the sizes in a human-readable format

  • Display the sizes of the folders:
  • du -sh *

    s : do not display the sub-directories
    h : display the sizes in a human-readable format

  • Display disk usage statistics:
  • df -h

  • Unzip in another directory:
  • tar zxvf archive.tar.gz -C /target_folder/

  • Show the last 5 lines of a file:
  • head file.txt

  • File rights:
  • chmod [-R] XXX file_name

    The first X corresponds to the rights of the file owner.
    The second X corresponds to the rights of the users in the file group.
    The third X corresponds to the rights of all users.

    Values of XXX:
    Xrwx
    0000
    1001
    2010
    3011
    4100
    5101
    6110
    7111

  • Take back control in a terminal: do CTRL-Z then type 'bg'.

  • Launch a process by making it independent of the terminal:
  • nohup the_process &

  • Detach a process from the terminal:
  • disown pid_process

    where pid_process is the PID of the process given by the command ps.

  • Launch several commands in only one line:

    • without taking into account the result of the previous command:
    • command1 ; command2

    • if the previous commands has been completed successfully:
    • command1 && command2

    • if the previous command is not working properly:
    • command1 || command2

  • Locate an executable:
  • which executable_name

  • Load and run a shell script:
  • source file.sh

  • Planning of scheduled tasks:
  • crontab -l (read the file)
    crontab -e (edit the file)

    Format of the crontab file:
    m h d month dow commande

    m : minutes (0-59)
    h : hours (0-23)
    d : day of the month (1-31, *: all days)
    month : month (1-12, *: all months)
    dow : day of the week (0-6, 0: sunday)
    command : command to run

  • Read a file being written:
  • tail -f file

  • Tip for displaying in columns all directories in environment variables ($PATH, $PYTHONPATH, ...) :
  • echo $PATH | tr ':' '\n'

  • List the librairies required by an executable:
  • ldd executable_name

  • Launch Firefox with another profile:
  • firefox -P

  • Extract all pages from a pdf with the tool pdfseparate:
  • pdfseparate in.pdf out%d.pdf

  • Extract the pages I to J of a pdf with the tool pdfseparate:
  • pdfseparate -f I -l J in.pdf out%d.pdf

  • Merge several pdf files with the tool pdfunite:
  • pdfunite pdf1.pdf pdf2.pdf pdf3.pdf out.pdf

If you have any questions about these commands or if you know other useful commands, you can discuss them in the forum: Discussion forums.

Quick comments
There is no comment yet.

Use of cookies on this website:
- If you are not a member of this website, no cookie is intentionally stored on your computer.
- If you are a member of this website, cookies are only used to keep your connection after each visit. This option can be deactivated at will in your profile and is deactivated by default.
- No other information is stored or retrieved without your knowledge, neither your personal information nor any other whatsoever. If in doubt, do not hesitate to contact the administrator of this website .
- Even this information banner does not use cookies and will therefore be displayed constantly on each visit on all pages of the website.