Tag Info

Hot answers tagged

5

The root directory is /. The themes directory in the root directory is /themes. A path that starts with / is called an absolute path; it starts from the root directory. A path that doesn't start with / is called a relative path; it starts from the current directory of the program where you use it. For example, a bare file name with no directory indication is ...


4

Yes, it's possible. One way to do it might look like this: cd /den/of/gifs && \ for f in ./*t.gif; do mv -- "${f%%t.gif}.gif" "$f" done The ${var%%pattern} thing is standard/POSIX sh syntax for removing the longest string that matches pattern from the end of $var.


3

Assuming you are using bash (or zsh) and your mail agent is sendmail then: [[ -f "filename_$(date '+%m%d%Y')" ]] || echo "File is missing!" | sendmail myname@gmail.com Between [[ and ]] we test if file exists, and if not then print some message and send it to myname.


3

In bash or POSIX sh: for file in *.fastq.gz; do mv -- "$file" "${file%%_*}_${file##*_}" done


2

A crude way to do it: for f in /path/to/PDFs/*.pdf; do base=$( basename "$f" .pdf ) if [ ! -f /path/to/PNGs/"$base".png ]; then mv "$f" /path/to/garbage/ fi done


2

Welcome to Linux! A trick that will get you started here (and will save you from getting carpal tunnel in the future) is "tab completion": $ ls /med then press Tab to see $ ls /media/ If you press Tab again, you might see a list of possible options to continue the path, $ ls /media/ MyBigExternalDrive/ My Example Hard Drive/ or (if there is only ...


2

About your errors: find: The relative path `~/program_files/internet/SSH_tunneling/' is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove that entry from $PATH You have ~/program_files/internet/SSH_tunneling/ in your $PATH. That's a literal ~. That does not mean your home ...


2

If you want to stay with find and basename, this should work: find . -name "*.gif" ! -name "*t.gif" -execdir sh -c ' cp -- "$0" "$(basename "$0" .gif)t.gif"' {} \; This is performance- and resource-wise not the best option.


2

To make it even more compact and faster, you could use parallel: parallel mv {} {.}t.gif :::: <(find . -regex '.+[0-9].gif') The expression after :::: provides arguments for parallel. These arguments are then used using {}. The {.} represents the argument without the file-extension. So, in our case {} will be the file names of files without the t in ...


2

You can use find to only select the `.txt files from under some directory: find direct/direct? -name "*.txt" this would print out all the files, so you can check you got what you wanted, and not too much is going to be selected. The *.txt has to be quoted, otherwise the shell will try expand this to .txt files in the current directory. As for the ...


2

The pattern [a_]* matches names that start with either of the characters a or _. The pattern *[.csv] matches names that end with one of the characters ., c, s or v. To match names that start with a_, use -name 'a_*'. To match names that end with .csv, use -name '*.csv'. find ../ -name 'a_*' -a -name '*.csv' or equivalently find ../ -name 'a_*.csv' matches ...


1

There are many ways of doing this. If you just want to list the files, you can use ls: ls a_date\(s\)/*csv Or, with find: find .. -path '*a_date*/*csv' find ../allCSVs/a_date\(s\)/ -name '*csv'


1

If you want to copy all the .txt files in a directory, use a wildcard pattern: cp direct/direct1/*.txt target This copies all the .txt files that are in the directory direct/direct1 to the directory target (which must already exist). You can pass multiple patterns to copy files from multiple directories: cp direct/direct1/*.txt direct/direct2/*.txt ...


1

On Unix and Unix-like systems, . means the current directory. For example, ls . is the same as ls, it will list the contents of the current directory. So, when you run ./Desktop it finds a directory called Desktop that is under your current directory. You then get an error telling you that this is a directory and, therefore, cannot be executed as it is not a ...


1

Sample explanation: / (slash) means root, from the root of the filesystem. So, /home/yogesh/Desktop/Books starts from the root, then checks for home, under home check for yogesh and so on. This is called an absolute path. . (dot) means starting from current directory. So, if your current directory is /home/yogesh and you check for ./Desktop, it is there. ...


1

On unix (like on Windows), /foo is the location of a file or directory (absolute location, from the root directory: /). Whereas ./foo is a relative location (relative to the current directory)... You can omit the leading dot + slash and just write foo. By typing the command /Desktop or ./Desktop, you tell the shell to execute Desktop... Which can't be ...


1

You can use find ... -exec option: find . -name iaGambro_gambro.sql -exec bash -c ' select file do : Do something with "$file" break done ' bash {} +


1

Using xargs, it can be done in this way: find . -type f -print0 | xargs -0 file | grep -v 'image' But xargs is so yesterday. The cool kids use parallel today. Using parallel, it would be: find . -type f | parallel file | grep -v 'image' See. No use of -print0 and -0. parallel is really smart by itself. UPDATE For listing only the most recent 500 ...


1

For generic advice regarding processing of file names potentially containing spaces, see Why does my shell script choke on whitespace or other special characters? The difficulty with what you're trying to do is that there's no nice way to list the N most recent files with standard tools. The easiest way to do what you're doing here is to use zsh as your ...


1

Use "find" with "-print0" option & pipe the output to "xargs" with "-0" option. Even though I know (and use) this technique, I see that user @Jens has answered a similar question, where you can find more Details : http://stackoverflow.com/questions/16758525/use-xargs-with-filenames-containing-whitespaces


1

I have two crude suggestions that might help. Neither feels particularly satisfying though, so perhaps something better will come up. First, use sed to add quotes to everything, so you'd only end up with trouble if there are quotes in the file name like ls -t | head -500 | sed -e 's/\(.*\)/"\1"/' | xargs file | grep -v 'image' The other is to use the ls ...


1

Using perl's rename (named prename in Ubuntu) prename 's/^([^_]*).*(_R.*)/$1$2/' *.fastq.gz


1

With zsh: autoload zmv # best in ~/.zshrc zmv '(*)_*(_R*)' '$1$2'


1

Shell script extensions are quite useful. For example I often write scripts that have multiple files in multiple languages (eg. bash, awk and lua) in the same directory. If I need to search for a string in only the bash files, the extension makes this very handy, to reduce false positives. Or if I want to do a line count of all my bash code for that project. ...



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