1
vote
2answers
101 views

Rename a file dynamically containing spaces [duplicate]

I want to rename a file dynamically based on data which contains spaces Name="Abc DEF" Name1="GHI JKL" mv /sample/pdf/noriginalName.pdf /sample/outputPdf/${NAME}${Name1}".pdf" But it gives me an ...
3
votes
2answers
33 views

How to build space separated, escaped full paths of files recursively matching glob?

I have a program which requires paths to files as arguments, which cannot be quoted and must not depend on working dir. Can this be done without chaining multiple xargs, tr, find, readlinks? Example ...
19
votes
2answers
794 views

Tilde (~) inside working unix directory

So, Im working in a UNIX environment and I noticed that inside my working directory, which is miles miles away from my UNIX home, there is a ~. Now, once in the past, I did rm -rf ~ from my working ...
0
votes
2answers
43 views

How to create a variable $ldir at your home directory that contains the relative path to letters?

If there's a directory on your Desktop called letters: 1) How to create a variable $ldir at your home directory that contains the relative path to letters? 2) How to copy a text file f1.txt to the ...
3
votes
1answer
90 views

How to find all paths not compatible with Windows?

On most Linux filesystems, NUL (\0) is the only invalid character in paths (and / is reserved as the path separator). Windows has a complicated set of rules for valid paths. Rather than fixing paths ...
1
vote
3answers
87 views

Copying the full path of a file to text file

I want to get the full path of all files in a directory and and the entire path has to be saved in one text file. Can you give me the script for that?
2
votes
3answers
73 views

Make grep work for special filenames

I have a set of txt files whose names may contain space or special characters like #. I have a grep solution grep -L "cannot have" $(grep -l "must have" *.txt) to list all the files who have must ...
2
votes
2answers
193 views

grep and directories containing spaces

I would like to search all files containing an association of strings (here the files should contain 'arthur' AND ('déni' OR 'deni') for instance) in a directory and subdirectories. After some search ...
1
vote
1answer
76 views

Command works with tilde at the end. How?

I'm on Ubuntu. I have a script called myscripts in /usr/bin/myscripts This script simply changes the current directory to ~/Work/MyScripts Normally, I simply open a terminal and type ~/Desktop$ . ...
1
vote
7answers
237 views

what are some uses of .(single period) & ..(double period) in the shell command line

The single period . means current working directory The double period .. means parent of the current working directory I can only think of . being used in relative pathname etc cd ./bin/usr How are ...
0
votes
2answers
120 views

Handling files with whitespace in their names

I have a lot of files that I need to sift through, specifically grep for certain keywords IN THE FILE, not he FILENAME. I have some 300+ files on a filesystem (so the files are within multiple ...
2
votes
2answers
408 views

Extracting parts of filename

I'm trying to use a part of the file name to be inserted into a new file created using the script. For eg: dcn_2014_01_31_14_17_45_505.pcap and dcn_2014_01_31_14_32_27_656.pcap should give ...
11
votes
2answers
2k views

What is the difference between “du -sh *” and “du -sh ./*”?

The title says it all. What's the difference between those 2 commands? NOTE: I'm more interested in the * and ./* part.
9
votes
3answers
2k views

identify files with non-ASCII or non-printable characters in file name

In a directory size 80GB with approx 700,000 files, there are some file names with non-English characters in the file name. Other than trawling through the file list laboriously is there: An easy ...
12
votes
2answers
550 views

Shell filename pattern that expands to dot files but not to `..`?

Recently I had a little mishap caused by a shell pattern that expanded in an unexpected way. I wanted to change the owner of a bunch of dot files in the /root directory, so I did chown -R root .* ...
6
votes
2answers
419 views

How does GLOBIGNORE work?

According to bash's manual page: GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a ...
6
votes
3answers
145 views

How can I determine a file's conventional filename extension

The file command is good at determining file types for my needs. Is there any way to map those results to conventional filename extensions?
3
votes
1answer
156 views

How can there be a directory named `~`?

I was trying to test out this buggy/new tool to see how it works, and it prompted me to choose a directory to use for stuff I am doing. From the directory ~/Code/indep, I typed in ...
3
votes
1answer
99 views

Test for link with trailing slash?

I created in /tmp/test/ mkdir somedir ln -s somedir/ somelink I want to loop through only directories: for file in */ ; do if [[ -d "$file" && ! -L "$file" ]]; then echo "$file is a ...
22
votes
3answers
594 views

shellcheck is advising not to use basename: why?

I am trying out shellcheck. I have something like that basename "${OPENSSL}" and I get the following suggestion Use parameter expansion instead, such as ${var##*/}. From the practical point of ...
1
vote
2answers
482 views

Way to write new filename on wildcard input?

I have some experience with Inix terminals from science internships I've been part of, mainly using a few utilities like grep, awk, and sed but there is one thing I've been trying to figure out for a ...
3
votes
2answers
59 views

Is there a way to condense ../.. parts of a path out programatically?

Say for example I have these types of paths to files in a script: /path/to/some/file/../../file1.txt Is there a command I can call such as readlink that will convert this path to its actual ...
3
votes
3answers
471 views

How to find file/directory names that are the same, but with different capitalization/case?

How can I list the file/directory names in a directory recursively that are the same, but with different capitalization/case? ex.: INPUT (not the ls command, the directories): [user@localhost ...
1
vote
1answer
251 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
4
votes
5answers
196 views

Standard unix util to split “foo.bar.baz” into “foo.bar” + “.baz”?

I want to split a string $basename, containing the output in two parts, $stem and $ext, such that: the string "${stem}${ext}" is identical to the original string $basename; either $stem or $ext may ...
2
votes
2answers
2k views

What does the tilde (~) mean at the end of a filename? [duplicate]

What is the file with the ~ at the end of the filename for? $ ls # aliased to add flags -rwxrwxr-x 1 durrantm 2741 May 16 09:28 strip_out_rspec_prep_cmds.sh~* drwxrwxr-x 13 durrantm 4096 May 16 ...
1
vote
1answer
219 views

How to prevent double escaping?

I'm trying to put a bunch of images together into a pdf. I ran gm convert *.jpg out.pdf and it worked, but the images were not in the right order. I found that ls -v orders them correctly so then I ...
7
votes
1answer
359 views

What is the significance of the dot in bash commands and how is it different from an asterisk?

I'm trying to understand the significance of the dot in bash and how it differs from an asterisk. Can someone please elaborate? For example, what's the difference between cp -ar /foo/. /foo2/ and cp ...
4
votes
3answers
2k views

Manipulate file name piped from find command

I'm relatively new to Bash and am trying to do something that on the surface seemed pretty straightforward - run find over a directory hierarchy to get all of the *.wma files, pipe that output to a ...
0
votes
1answer
159 views

Create a File with Touch on a specific Directory

I want a create a file with a specific extension(.done). I am using the command touch. Something Like: touch `basename $UNZIPFILE`".done" It's creating the file but in current directory. I want to ...
0
votes
1answer
76 views

Find and use the path of a file?

I'm trying to find the path of a file and move it. When I try realpath, it is not useful. For example : I want to move the file All Hail the Generalist - Vikram Mansharamani - Harvard Business ...
1
vote
2answers
862 views

Reserved characters in file names

I was under the impression that the only character not allowed in file names was /, but I don't seem to be able to create a file whose name contains characters such as *, \, ", :, |, < or > ...
24
votes
2answers
5k views

What does dash “-” at the end of a command mean?

Given the following command: gzip -dc /cdrom/cdrom0/file.tar.gz | tar xvf – What does the - at the end of the command mean? Is it some kind of placeholder?
2
votes
4answers
2k views

chown all files based on file name pattern in current directory

I'm trying to chown all files whose filenames begin with ChownFileNames. I've used this command, but it doesnt seem to work: find . -maxdepth 1 |grep 'ChownFileNames*' -exec chown hadoop:hadoop -- {} ...
1
vote
2answers
134 views

How to copy a file and move it to a location using unix

I need a file to stay in the same location but also move it to a different location. What am I doing wrong? cp RubyTest.sublime-settings \ ~/Library/Application Support/Sublime\ Text\ ...
7
votes
3answers
958 views

Change the color of the file name text

I am writing scripts to initialize and configure a large system with many components. Each component has its own log file. I would like to change the color of the component file name to red whenever ...
2
votes
3answers
469 views

Rename a lot of files with all types of characters, with POSIX portability

Sometimes I need to rename all the files (the renaming convention follows later) in a directory where the filename is always in the form of 'filenamename.extension' (extension always exists and ...
5
votes
4answers
6k views

Split a file by line and have control over resulting files extension

There is a standard command for file splitting - split. For example, if I want to split a words file in several chunks of 10000 lines, I can use: split -dl 10000 words wrd and it would generate ...
2
votes
3answers
189 views

Selecting latest files and grouping by name

I have a directory containing files of the following name structure. <device>.<yyyy-mm-dd-hh-mm-ss> I am working on a script that will retain the the last X copies of these ...
14
votes
4answers
10k views

Converting relative path to absolute path

Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
6
votes
1answer
1k views

Best way to remove file extension from a string?

So, I'm using a script I've made to convert videos to the webm format. A certain program calls the script, sending %f which is the full, absolute file name of the video, like this: converter.sh %f ...
4
votes
3answers
3k views

How do I move some but not all files from one directory to another?

I need to move my files from one directory to other. But there is some issues. My file name pattern is like: apple.0, apple.<n>, n -> {0,1,2,3 ...~ } so mv apple.* will not work, because ...
7
votes
4answers
546 views

How can I find a file whose name includes a given string, such as “abcde”?

Within a set of directories, how do I find a file whose name includes a given string, such as "abcde"?
3
votes
1answer
815 views

shopt -s nocaseglob is not working on Ubuntu

Case insensitive file name globbing is not working in bash on Ubuntu 11.04 64bit. The shell options specified in .bashrc are as follows: shopt -s nocaseglob shopt -s nocasematch shopt also shows ...
3
votes
2answers
177 views

returning strings corresponding to shell glob matching

Suppose I have a subdirectory called sub. Then I want to operate on all files in that directory with the extension "txt". I want something like for f in sub/*.txt do enscript -b "" -o {$f ...
17
votes
3answers
6k views

bulk rename (or correctly display) files with special characters

I have a bunch of directories and subdirectories that contain files with special characters, like this file: robbie@phil:~$ ls test�sktest.txt test?sktest.txt Find reveals an escape sequence: ...
16
votes
6answers
13k views

Grabbing the extension in a file name

How do I get the file extension from bash? Here's what I tried: filename=`basename $filepath` fileext=${filename##*.} By doing that I can get extension of bz2 from the path /dir/subdir/file.bz2, ...