Linux commands - Tuertolin/Linux GitHub Wiki

Bash - Hide full path

export PS1='\u@\h: '

That results in oli@bert: for my prompt.

If you really want something as minimalist as you ask for, try this: export PS1='> '

You can attach that to the end of your ~/.bashrc file to have it persist between logins.

You can also get creative with some colours. Here's what I use on my servers: export PS1='\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[00m\]: '

Just to expand on Oli's answer (and so that I have a bookmark for those short-hand symbols):

The bash prompt (stefano@linux:~$) is only the first of a couple of prompts you might see:

PS1: the default prompt you see when you open a shell

It's value is stored in an environment variable called PS1. To see its value, type

echo $PS1

This will give you something like

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

To change it, you can set a new value for the variable:

export PS1="\u > "

This will result in a prompt like this:

stefano > 

PS2: is your secondary prompt. This gets shown when a command is not finished. Type echo "asd and hit enter, the secondary prompt will let you enter more lines until you close the inverted commas.

PS3 is the prompt used for select(2)

PS4 is the prompt used for alt text stack traces (default: +)

To make the changes permanent, you append them to the end of .bash_profile (or .bashrc, see this question) in your home directory.

Here's a more or less complete list of shorthand that you can use when composing these:

\a     The 'bell' character
\A     24h Time
\d     Date (e.g. Tue Dec 21)
\e     The 'escape' character
\h     Hostname (up to the first ".")
\H     Hostname
\j     No. of jobs currently running (ps)
\l     Current tty
\n     Line feed
\t     Time (hh:mm:ss)
\T     Time (hh:mm:ss, 12h format)
\r     Carriage return
\s     Shell (i.e. bash, zsh, ksh..)
\u     Username
\v     Bash version
\V     Full Bash release string
\w     Current working directory
\W     Last part of the current working directory
\!     Current index in history
\#     Command index
\$     A "#" if you're root, else "$"
\\     Literal Backslash
\@     Time (12h format with am/pm)

You can of course insert any literal string, and any command:

export PS1="\u $(pwd) > "

Checked the location of your current working directory pwd

At the beginning of a script, add #!/bin/bash Then you will be able to run the command from anywhare. #!/bin/bash

EXCELLENT https://linuxconfig.org/bash-scripting-tutorial-for-beginners

Change password

passwd

Permissions

stat -c "%a %n" *

List users

cut -d: -f1 /etc/passwd getent passwd

History commands

history > print.txt

Using scp to transfer data “scp” means “secure copy”, which can copy files between computers on a network. You can use this tool in a Terminal on a Unix/Linux/Mac system.

To upload a file from your laptop to Amazon instance:

$scp -i ~/Desktop/amazon.pem /Desktop/MS115.fa [email protected]:/data/ This command will upload a file - MS115.fa in your ~/Desktop/ folder of your laptop to folder ~/data/ on an Amazon instance. Note you still need to use the private key you used to connect to the Amazon instance with ssh. (In this example, it is the amazon.pem file in ~/Desktop/.

Note: You need to make sure that the user “ubuntu” has the permission to write in the target directory. In this example, if ~/data/ was created by user “ubuntu”, it should be fine.

Similarly, to download a file from Amazon instance to your laptop:

$scp -i ~/Desktop/amazon.pem [email protected]:/data/ecoli_ref-5m-trim.fastq.gz ~/Download/ This command will download a file /data/ecoli_ref-5m-trim.fastq.gz from Amazon instance to your ~/Download folder in your laptop.

Note: You can use asterisk(*) to download multiple files, like *.fasta.gz.

Searching files

https://www.howtoforge.com/tutorial/linux-search-files-from-the-terminal/

Orginize folders by size

du -hs * | sort -h

List of running services under systemctl

ystemctl | grep running

systemctl list-unit-files | grep enabled

How to use Systemctl (Genial)

https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units

How to check open ports

List Users

cut -d: -f1 /etc/passwd

cat /etc/passwd

Create users

sudo adduser <username>

List groups

groups

To add an existing user to an existing group you can use the same command:

sudo adduser <username> <groupname>

Byobu

https://byobu.org/index.html

Split screen horizontally:
    Shift+F2 or
    Ctrl+A then |

Split screen vertically:
    Ctrl+F2 or
    Ctrl+A then %

Switch focus:
    Shift+↑ ↓ ← → or
    Ctrl+A then ↑ ↓ ← →

You can easily toggle on/off the use of the F-keys inside of Byobu (tmux) by pressing either:

shift-F12 (in tmux)

ctrl-a-! (in screen)

How to burn an ISO file to a usb drive

dd

Let’s break that down.

sudo: You need to be a superuser to issue dd commands. You will be prompted for your password. dd: The name of the command we’re using bs=4M: The -bs (blocksize) option defines the size of each chunk that is read from the input file and wrote to the output device. 4 MB is a good choice because it gives decent throughput and it is an exact multiple of 4 KB, which is the blocksize of the ext4 filesystem. This gives an efficient read and write rate. if=Downloads/ubuntu-19.04-desktop-amd64.iso: The -if (input file) option requires the path and name of the Linux ISO image you are using as the input file. of=/dev/sdb: The -of (output file) is the critical parameter. This must be provided with the device that represents your USB drive. This is the value we identified by using the lsblk command previously. in our example it is sdb, so we are using /dev/sdb. Your USB drive might have a different identifier. Make sure you provide the correct identifier. conv=fdatasync: The conv parameter dictates how dd converts the input file as it is written to the output device. dd uses kernel disk caching when it writes to the USB drive. The fdatasync modifier ensure the write buffers are flushed correctly and completely before the creation process is flagged as having finished.

⚠️ **GitHub.com Fallback** ⚠️