Questions tagged [filenames]
File name is a name used to identify a file uniquely on given file system.
231
questions
218
votes
8
answers
40k
views
Why is looping over find's output bad practice?
This question is inspired by
Why is using a shell loop to process text considered bad practice ?
I see these constructs
for file in `find . -type f -name ...`; do smth with ${file}; done
and
for ...
151
votes
6
answers
29k
views
How does Linux handle multiple consecutive path separators (/home////username///file)?
I'm working on a python script that passes file locations to an scp subprocess. That's all fine, but I'm in a situation where I may end up concatenating a path with a filename such that there's a ...
233
votes
9
answers
308k
views
Looping through files with spaces in the names? [duplicate]
I wrote the following script to diff the outputs of two directores with all the same files in them as such:
#!/bin/bash
for file in `find . -name "*.csv"`
do
echo "file = $file";
diff $...
51
votes
4
answers
19k
views
How to find out which (not installed) Debian package a file belongs to?
On Debian systems (and derivatives):
$ dpkg --search /bin/ls
coreutils: /bin/ls
That is, the file /bin/ls belongs to the Debian package named coreutils.
But this only works if the package is ...
217
votes
11
answers
177k
views
List files sorted numerically
I have a bunch of files from log1 to log164.
I'm trying to LIST the directory (sorted) in a UNIX terminal but the sort functions are only providing the format like this:
home:logs Home$ ls -1 | sort
...
60
votes
3
answers
20k
views
unix, difference between path starting with '/' and '//' [duplicate]
In unix/linux, any number of consecutive forwardslashes in a path is generally equivalent to a single forwardslash. eg.
$ cd /home/shum
$ pwd
/home/shum
$ cd /home//shum
$ pwd
/home/shum
$ cd /home///...
55
votes
16
answers
33k
views
How can I delete a file which filename has non-printing characters
I somehow managed to create a file that doesn't seem to have a filename. I found some information regarding how to get more details of the file in the following thread.
However, I tried some of the ...
125
votes
9
answers
12k
views
On what systems is //foo/bar different from /foo/bar?
Throughout the POSIX specification, there's provision (1, 2, 3...) to allow implementations to treat a path starting with two / specially.
A POSIX application (an application written to the POSIX ...
33
votes
2
answers
3k
views
Security implications of running perl -ne '...' *
Apparently, running:
perl -n -e 'some perl code' *
Or
find . ... -exec perl -n -e '...' {} +
(same with -p instead of -n)
Or
perl -e 'some code using <>' *
often found in one-liners ...
35
votes
2
answers
11k
views
Why does inode value change when we edit in "vi" editor?
When I edit a file in the vi editor, the inode value of the file changes. But when edited with the cat command, the inode value does not change.
31
votes
2
answers
40k
views
What is the difference between "du -sh *" and "du -sh ./*"?
What's the difference between du -sh * and du -sh ./* ?
Note: What interests me is the * and ./* parts.
6
votes
1
answer
10k
views
Rename All Files with a Certain Name
I'm trying to find certain files with the name "stringx" and replace the name (but not the extension) with "stringy". So basically for stringx.txt and stingx.cs, I'd want stringy.txt and stringy.cs. I'...
87
votes
4
answers
66k
views
When should I use a trailing slash on a directory? [duplicate]
Possible Duplicate:
How linux handles multiple path separators (/home////username///file)
Most commands I use in linux behave exactly the same whether I include the trailing slash / character on ...
26
votes
4
answers
25k
views
Is it correct to use certain special characters when naming filenames in Linux?
Is it correct to use certain special characters, as +, &, ', . (dot) and , (comma), basically, in filenames.
I understand that you can use - and _ with no problem, but doing some research I have ...
25
votes
3
answers
61k
views
What are ./ and ../ directories?
Simple question, but I'm not sure where to look and google doesn't respond to periods and slashes.
I'm just trying to count the # of files & directories in the current directory (not including ...
18
votes
3
answers
27k
views
Why are filenames that start with a dot hidden? Can I hide files without using a dot as their first character?
Initially I thought it was a coincidence, but now I see there's even a tag for it: all hidden file names start with a dot. Is this a convention? Why was it chosen? Can it be changed? Or in other words ...
85
votes
6
answers
32k
views
recursive statistics on file types in directory?
I did a website scrape for a conversion project. I'd like to do some statistics on the types of files in there -- for instance, 400 .html files, 100 .gif, etc. What's an easy way to do this? It has to ...
33
votes
2
answers
28k
views
Remove prefixes from filenames
I have a bunch of files as follows:
04602635_b0294.DAT20120807164534
04602637_b0297.DAT20120807164713
04602638_b0296.DAT20120807164637
04602639_b0299.DAT20120807164819
04602640_b0298....
16
votes
1
answer
12k
views
What does *~ mean?
At the end of a makefile I saw
rm -f *~ *.class
I understand the *.class, but what's *~?
58
votes
3
answers
121k
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
It would generate several ...
32
votes
4
answers
38k
views
dirname and basename vs parameter expansion
Is there any objective reason to prefer one form to the other? Performance, reliability, portability?
filename=/some/long/path/to/a_file
parentdir_v1="${filename%/*}"
parentdir_v2="$(dirname "$...
31
votes
5
answers
99k
views
Extract file name from path in awk program
I have an awk script and I have passed a CSV file to it.
awk -f script.awk /home/abc/imp/asgd.csv
What am I doing is to get FILENAME within script.awk. FILENAME gives me the whole path. As I am in ...
3
votes
1
answer
1k
views
Redirect a file descriptor before execution
I know that I can change the file a program writes to by interrupting the process in gdb, closing using the file descriptor and then re-opening with the file name I want. Is there a way to do the same ...
112
votes
2
answers
41k
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?
77
votes
8
answers
92k
views
Converting relative path to absolute path without symbolic link
Is there a Unix command to get the absolute (and canonicalized) path from a relative path which may contain symbolic links?
29
votes
3
answers
6k
views
Newlines in filenames
I understand and accept the premise that defensive1 shell scripting is both prudent and, in the longer term, more sustainable.
Many of the answers to text processing questions here follow this ...
11
votes
2
answers
4k
views
Trailing slashes on symbolic links to directories
I'm trying to emulate the process of path resolution (see man page path_resolution) in unix-like systems.
My OS is Linux with GNU coreutils 8.7.
In order to clarify the meaning of extra trailing '/' ...
7
votes
4
answers
5k
views
How to find missing files with sequential names? [duplicate]
I have thousands of files named 1.txt 2.txt and so on. Some of those files are missing. Which would be the easiest way to find out which files are missing?
7
votes
1
answer
4k
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
...
6
votes
5
answers
24k
views
Stripping directory paths to get file names
What I am doing is converting mp3's with LAME. I already have an old script I wrote that works but I want to add to it this ability--to no longer delete the file but instead save it in a new root ...
4
votes
6
answers
17k
views
File extensions and association with programs in linux
In windows we can associate a file's extension with programs.
E.g. a file test.pl can be run by the installed Perl interpreter due to the pl extension.
In linux though it needs #!/usr/bin/perl as the ...
50
votes
10
answers
84k
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, but ...
27
votes
3
answers
2k
views
Why does awk stop and wait if the filename contains = and how to work around that?
awk 'processing_script_here' my=file.txt
seems to stop and wait indefinitely...
What's going on here and how do I make it work ?
26
votes
9
answers
6k
views
Clipboard for copying and pasting files in command line?
In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it ...
26
votes
3
answers
15k
views
Understanding Unix file name encoding
I have a hard time understanding how the file name encoding works. On unix.SE
I find contradicting explanations.
File names are stored as characters
To quote another answer:
Several questions about ...
23
votes
9
answers
58k
views
Count files in a directory by extension
For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another ...
17
votes
6
answers
139k
views
how to extract part of a filename before '.' or before extension
I have files in format below:
abc_asdfjhdsf_dfksfj_12345678.csv
hjjhk_hkjh_asd_asd_sd_98765498.csv
hgh_nn_25342134.exe
I want to get the value before the . and after the last _.
The result would ...
5
votes
6
answers
3k
views
How do I remove a file I accidentally created named $file?
I was working on a shell script and I accidentally created a file with the variable as its name. Now I have $file in my ls output, and cannot remove it. What can I do?
85
votes
1
answer
110k
views
How to list files in a zip without extra information in command line
In my bash command line, when I use unzip -l test.zip I get the output like this:
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
810000 05-07-2014 15:09 ...
58
votes
3
answers
55k
views
What charset encoding is used for filenames and paths on Linux?
Does it depend on what file system I use? For example, ext2/ext3/ext4 but also what happens when I insert one of those "joliet" CD-ROMs with ISO 9660? I've heard that POSIX contains some sort of spec ...
58
votes
7
answers
130k
views
File extensions for unix shell scripts [closed]
On wikipedia, the article for .sh says:
For the .sh file extension type, see Bourne shell.
How about other unix shells?
I know that the shebang is used inside the file to indicate an ...
42
votes
5
answers
14k
views
Glob with Numerical Order
I have this list of pdf files in a directory:
c0.pdf c12.pdf c15.pdf c18.pdf c20.pdf c4.pdf c7.pdf
c10.pdf c13.pdf c16.pdf c19.pdf c2.pdf c5.pdf c8.pdf
c11.pdf c14.pdf c17.pdf c1.pdf ...
36
votes
1
answer
14k
views
rsync: colon in file names
Other than by renaming the files first, how can I rsync files that may have colons in their names?
36
votes
2
answers
61k
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 14:...
29
votes
3
answers
64k
views
What does the ./ mean (dot slash) in linux?
For example, I can do the following
touch a
or
touch ./a
Then when I do ls I can view both, so what exactly is the ./ for?
22
votes
9
answers
38k
views
Displaying file names with contents when using the "cat" command
Is there a command to show the directory or file name when using cat to display the contents of files?
For example: assume two files f1.txt and f2.txt are in ./tmp
./tmp/f1.txt
./tmp/f2.txt
Then ...
20
votes
3
answers
27k
views
How to exclude some files from filename expansion mechanism in bash?
I have ubuntu file system directories in the root directory and I accidentally copied hundreds of files into root directory.
I intuitively tried to remove copied files by excluding file system like
...
10
votes
2
answers
5k
views
Is it possible to fake a specific path for a process?
I'm trying to run ADB on a linux server with multiple users where I am not root (to play with my android emulator). The adb daemon writes its logs to the file /tmp/adb.log which unfortunately seems to ...
10
votes
2
answers
37k
views
passing filename with spaces to a shell script [duplicate]
The shellscript is very simple:
retroarch $* -c /tmp/retroarch/Data/retroarch/gambatte.cfg
("retroarch" is another shellscript)
If the filename passed contains spaces it fails:
RetroArch [ERROR] ::...
9
votes
1
answer
5k
views
Handling names with leading dash in bash shell [duplicate]
How can I handle (e.g. apply mv command) in a command shell the files with leading dash (-) in names? The command
mv -weirdfilename.zip normalfilename.zip
naturally accepts - at the beginning of a ...