- 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!
-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
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 # set "FOO" as environment variable VARIABLE
export VARIABLE="FOO"
# remove variable VARIABLE from environment
unset VARIABLE- Most if not all environment variables are uppercase!
# 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# 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- 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.00du 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
# 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"Takes a string as an argument and evaluates it as if you'd typed that string on a command line
exit Exit with an exit code. Any non-zero exit code will be interpreted as exited with an error.
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"' \; -printBring 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 Reveals the name of the host Example: molev209
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
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
Killing defunct processes. For example when Firefox crashes ps -e | grep firefox kill -9 <process_id_of_firefox>
Symbolic links
ln -s
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
ls --full-time
lsof | grep '.nfs00000000107c4e6200248a94'
man -l Will open the file with man man ./ Will open the file with man
# 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 777tmp=$(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
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.fastanohub Continue running the program even if the session ends
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 -f <file.txt> Returns the absolute path of the file If realpath is not available
realpath <file.txt> Returns the absolute path of the file
reboots the system
rsync
For updating chain backups, this command is really useful rsync -avP --inplace --append chain*.* chain_backup/
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 -r +5 "Rebooting soon, log out ASAP!" Gives people who are logged in some time to log out.
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 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 [cmd] Will print out the time it takes to execute a given command
Prints system information -a Prints all information
Prints among other stuff, hostname, 32-bit or 64-bit
Shows you who is currently logged in
wget <source_url> -P <out_dir>
whatis Gives a oneline summary of what the is
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 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