Skip to content

Latest commit

 

History

History
416 lines (288 loc) · 12.5 KB

File metadata and controls

416 lines (288 loc) · 12.5 KB

FILE PERMISSIONS

  • Either (r)ead, (w)rite, or e(x)ecute on 'user', 'group', 'others'

Example: -rw-r--r-- User can read and write, group and others can only read

The first column can either be

- regular file
d directory
l symlink
  • Execute permissions are necessary to remove directories

  • To read a file, a user must have Execute (x) permissions on every single directory in the path leading to that file.

  • To check the permissions for all those directories, use namei -l /path/to/file. To get all upstream permissions, ensure you provide the absolute path!

FILE OWNERSHIP

-rwxr-----+  1 jmartijn roger     2065 Jul 23 15:34 run_esmfold2.tugba.py
  • As jmartijn, I can not change the ownership of this file. You need administrative privileges (e.g. using sudo, or as root) to do this

  • However, I can change the user, group, or others permissions with chmod

WILDCARDS

The * character can be used as a wildcard:

# List anything that ends with .fasta
ls *.fasta

# List anything that ends with number.fasta
ls `*[0-9]`.fasta

# List anything that ends with 350, 450, 550
ls `*[3-5][5]`0.fasta 

ENVIRONMENT STUFF

# set "FOO" as environment variable VARIABLE
export VARIABLE="FOO"

# remove variable VARIABLE from environment
unset VARIABLE
  • Most if not all environment variables are uppercase!

Typical environment variables

# Contains all directories that contain executables 
# that can be directly invoked from the command line
$PATH

# Contains the absolute home directory
$HOME

# Contains current absolute directory
$PWD

# The username
$USER

# The program running the current shell (bash, zsh, csh, etc)
$SHELL

SYSTEM INFORMATION

# Name and version of current operating system
cat /etc/os-release

# Bunch of info per CPU on the computer
cat /proc/cpuinfo

# Reports the number of cpus, architecture, 
# and all other relevant CPU information of the system
lscpu

UNIX UTILITIES useful for system administration

CRONTAB

  • Crontab jobs are preset commands that execute always on certain days at certain times
# List all current crontabs
crontab -l

# Edit crontab commands
crontab -e

# crontab command format:
# [minute] [hour] [day of the month] [week] [month] [day of the week]

# Example
# 0 12 * * * *        Every day, at 12.00

DU and DUST

du reports disk usage of directories or files

# Human readable numbers
du -h [file|directory]

# Nice quick command to look for the top
# biggest directories from current directory
du -h . | sort -h -r | head -n 20

# Report total size of dir only
# Will not report any nested directories or files
du -sh [dir]

dust is a modern rust-written utility that is very fast and can give you a graphical representation of the disk usage under the current directory

ECHO

# Prints string to STDOUT
echo "$STRING"

# Same thing but converts tabs to spaces
echo $STRING

# Enables interpretation of backslash escapes
# and certain characters are recognized, like \t and \n
echo -e "hello\tworld\n"

# Remove the trailing newline characters
echo -n "helloworld\n"

EVAL

Takes a string as an argument and evaluates it as if you'd typed that string on a command line

EXIT

exit Exit with an exit code. Any non-zero exit code will be interpreted as exited with an error.

FIND and FD

find <PATH> <flags> \;

-name <EXPRESSION>

# The level of directories down find will try to find your attern
-maxdepth <number>
-size 0
-exec <cmd> {}          {} refers to each file that was found
-xtype l                Find broken symlinks
-newermt "2022-05-10"   Find files that are newer (modified later) than May 10th 2022
-ls                     Print found files like an 'ls -l' print
 
# Example:
find . -name "All.htm"
find . -size 0 -exec rm {} \;   Remove empty files
find . -xtype l -exec rm {} \;  Remove broken symlinks

# sort all files in directory and subdirectories by modification time
find . -type f -printf '%TY-%Tm-%Td %TH:%TM: %Tz %p\n' | sort -n

# list all directories that do not contain a file that has pattern
find . -type d ! -exec sh -c 'ls "{}" | grep -q "PATTERN"' \; -print

FG

Bring back jobs that are running in the background, into the "foreground". Jobs that are running in the background can be displayed with "jobs". Ctrl-Z to put current windown in the background. Then you can use 'fg' to put it back to the foreground

HOSTNAME

hostname Reveals the name of the host Example: molev209

IDENTIFY

Reports properties of an image file. Part of the ImageMagick suite. Example: identify filename.png

Reports:

filename.png PNG 200x3510 200x3510+0+0 16-bit DirectClass 1.267MB 0.000u 0:00.000

JOBS

Lists all 'jobs', that can either be commands, or scripts or anything like that in the background. Putting an '&' sign after the job command puts it in the background. With FG (foreground), you put the 'job' back in the foreground. Then you can kill it for example. JOBS only lists those jobs that are running in that specific terminal

KILL

Killing defunct processes. For example when Firefox crashes ps -e | grep firefox kill -9 <process_id_of_firefox>

LN

Symbolic links ln -s Places a link to another file (so prevents additional space to be used) ln -s Automatically clips the path and only leaves the file name as the name of the link

LS

ls -S Sorts all files in directory by size ls -t Sorts all files in directory by last time modified ls -d */ List only directories ls -L List the file that the symbolic link is pointing to ls --ignore= List all files except those that match

get detailed time information of files

ls --full-time

LSOF

check which process is using a particular file

lsof | grep '.nfs00000000107c4e6200248a94'

MAN

man -l Will open the file with man man ./ Will open the file with man

MKDIR

# Create nested directories in a single command. 'p' stands for parent directory
# -p also prevents the 'does already exists' error if directory already exists
mkdir -p newdir1/newdir2

# Create directory with these permissions ??
mkdir -m 777

MKTEMP

tmp=$(mktemp) mktemp returns a random temporary file name and creates that file tmp_dir=$(mktemp -d) mktemp -d returns a random temporary directory name and creates that directory

NAMEI

This is a nice way to get the permissions of all directories leading up to your file and the file itself

$ namei -l /scratch3/jmartijn/ergo-genome/results/46_EditedPolishedGenome/Ergobibamus_cyprinoides_CL.scaffolds.edited.fasta

f: /scratch3/jmartijn/ergo-genome/results/46_EditedPolishedGenome/Ergobibamus_cyprinoides_CL.scaffolds.edited.fasta
drwxr-xr-x root     root  /
drwxr-xr-x root     root  scratch3
drwxr-x--x jmartijn roger jmartijn
drwxr-xr-x jmartijn roger ergo-genome
drwxr-xr-x jmartijn roger results
drwxr-xr-x jmartijn roger 46_EditedPolishedGenome
-rw-r--r-- jmartijn roger Ergobibamus_cyprinoides_CL.scaffolds.edited.fasta

NOHUB

nohub Continue running the program even if the session ends

PS

ps Shows a list of active processes with process IDs (PIDs) and the command used to start these processes ps -fu $USER Shows all actives processes invoked by $USER ps -o <field1,field2,etc> Show process key fields. Example: ps -o user,uid,comm,pid,pcpu,tty ps -r Sort by pcpu (%CPU)

PPID: Parent Process ID

READLINK

readlink -f <file.txt> Returns the absolute path of the file If realpath is not available

REALPATH

realpath <file.txt> Returns the absolute path of the file

REBOOT

reboots the system

RSYNC

rsync Options: -a Archive mode, keeps all symlinks, devices, attributes, permissions, ownerships etc. -v Verbose mode -z Compress data during transfer -h Human readable output -P --progress and --partial combined --partial If transfer breaks, you can restart it no problem later --progress Shows progress bars of transfer --log-file= Creates log of rsync transfer --delete-after Deletes files in the destination that are no long present in the source -L or --copy-links Rsyncs the file that the link is pointed to -p Preserve permissionsÎ -u or --update Skip files that are newer on the receiver -r or --recursive Tells rsync to copy directories recursively --exclude='.txt' Rsync all files except for those that end with .txt --exclude='' --include='*.txt' Exclude all files but do NOT exclude those ending with .txt --files-from=files.txt Rsync only the files that are listed in 'files.txt'. Example: rsync --files-from=files.list jmartijn@molev-32-72.icm.uu.se:/path/of/destination/ . Where files.list contained only file names, no paths or slashes etc. --exclude-from=files.txt Rsync all files except those listed in files.txt Make sure the filenames in files.txt are relative to , not necessarily from where you execute the command! --dry-run Do a dry-run. Execute a test operation without making any changes --inplace Update destination files in-place. Update file without creating a new file. Without --inplace, rsync would create a new tmp file, copy the updated parts onto it, swap with destination file, delete old copy of destination file --append Append data onto shorter files Append assumes that the destination file is a shorter version of the source file, meaning the destination file is identical to the start of the source file

For updating chain backups, this command is really useful rsync -avP --inplace --append chain*.* chain_backup/

SCREEN

screen Open up a new screen screen -S Create a new screen with screen -ls List down the current open screens screen -r Reattach to the screen screen -r Reattach to screen with the set sessionname screen -r If there is only one screen, it automatically will reattach to that one. exit Exit the current screen you are in (this will kill any processses in this screen?) killall screen Kill all screens

WHILE IN SCREEN ctrl-a + ctrl-d Detach from the screen while not interuppting any processes in the screen ctrl-a + ':' + sessionname + Enter Rename a session to something easy to remember ctrl-a + Esc You can now scroll up and down using arrow keys and PgUp PgDwn

SHUTDOWN

shutdown -r +5 "Rebooting soon, log out ASAP!" Gives people who are logged in some time to log out.

SSH

Login as root: Type either 'su' and then enter the root password or ssh into your own machine as root as follows: ssh -i .ssh/root_rsa root@molev209 and enter the passphrase for key '.ssh/root_rsa' (not the same as the root password) ssh -X enable X11-forwarding ssh -Y enable trusted X11-forwarding Once you are in the server, you can check if X11 server is active with echo $DISPLAY which should return something like 'localhost:15.0'

add ssh key so you only need to type passphrase once per session ssh-add ~/.ssh/perun_rsa

TAR

tar is short for "tape archive" tar -tvf Lists the contents of the .tar tar -ztvf Lists the contents of the .tar.gz tar -jtvf Lists the contents of the .tar.bz2 tar -czvf .tar.gz /path/to/dir-or-file> (Create) an archive with g(Z)ip, with (V)erbose and specify (F)ilename tar xzf <tar_ball> -C <output_dir>

TIME

time [cmd] Will print out the time it takes to execute a given command

UNAME

Prints system information -a Prints all information

Prints among other stuff, hostname, 32-bit or 64-bit

W

Shows you who is currently logged in

WGET

wget <source_url> -P <out_dir>

WHATIS

whatis Gives a oneline summary of what the is

WHEREIS

whereis Searches standard unix/linux locations, like /usr/local/bin, /usr/bin, /bin/ etc for Shows ALL locations of where a tool is installed. For instance whereis python can show you all different python installations

WHICH

which Searches your $PATH for the executable that is and returns the directori(es) in your $PATH that have said

which -a Lists all locations at which command is installed