Tag Info

Hot answers tagged

5

If you run the script below in the background, it checks for mounted volumes. If one of your defined drives is mounted, it automatically opens the set folder in nautilus. A minor problem was that nautilus does not support opening a directory in a new tab from command line, only in a new window. That means that the initial window, that appears if you insert ...


2

Move the entire bash command to a script (say, in /some/path/sync.sh): #! /bin/bash for i do EXT="${i##*.}" EXT=${EXT,,} if [[ "${EXT}" == *"/"* ]] then EXT="no_extension"; fi mkdir -p "${DEST}/${EXT}" rsync -a "$i" "${DEST}/${EXT}" done Then call the find thus: SRC="/src" export DEST="/dest" find "${SRC}" ...


2

sudo echo " auto lo:1 iface lo:1 inet static address $1 netmask $2" | sudo tee /etc/network/interfaces The last line on your script netmask $2" >/etc/network/interfaces attempts to edit the interfaces file which only root can write to. (Or at least it should be owned by root) However, sudo echo "" > likely does not work how you want it to. ...


2

awk -F',' '$N == "string to search"' filename.csv Replace N with column number and filename.csv with filename to search


2

Use this script: #! /bin/bash # for i in $(cat /etc/passwd | cut -d: -f1); do echo -n $i ": " grep $i /etc/group | cut -d: -f1 | tr "\n" " " echo done It will list all users in the system (included system) and print the list of groups near them. With a trivial modification you can print the numeric id too.


1

When in a terminal just run the following command. uptime This will display your current uptime plus a little ekstra information. Mine says. 08:44:21 up 1:05, 2 users, load average: 0,00, 0,01, 0,05 So my uptime is 1 hour and 5 minutes. In a bash script to only get the uptime I'd use uptime | awk '{print $3}' This will show only the 3rd section of ...


1

Use echo $SECONDS , gives you the uptime of a terminal in seconds.


1

I don't think sudo is doing what you think it's doing. What's actually going on is that sudo is only affecting the echo command - it won't actually output what you need to the /etc/network/interfaces/ file because sudo doesn't actually cover the >. So what can you do? You have two options: reformat your command to work like the one provided in the ...


1

If you're looking for a specific file, why run a loop? You can directly test for the existence of that file: if [[ -f $source ]] then dstfile=$(basename "$source") ... fi



Only top voted, non community-wiki answers of a minimum length are eligible