Questions tagged [filenames]

File name is a name used to identify a file uniquely on given file system.

Filter by
Sorted by
Tagged with
190
votes
8answers
25k 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 ...
180
votes
10answers
237k 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 $...
165
votes
11answers
134k 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 ...
126
votes
6answers
24k 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 ...
118
votes
9answers
11k 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 ...
92
votes
2answers
32k 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?
79
votes
5answers
28k 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 ...
75
votes
8answers
82k 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?
72
votes
1answer
87k views

Which Fedora package does a specific file belong to?

In the Debian family of OSes, dpkg --search /bin/ls gives: coreutils: /bin/ls That is, the file /bin/ls belongs to the Debian package named coreutils. (see this post if you are interested in a ...
71
votes
14answers
69k views

Unix file naming convention [closed]

I was wondering what is the naming convention for files in Unix? I am not sure about this, but I think there is perhaps a universal naming convention that one should follow? For example, I want to ...
70
votes
4answers
50k 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 ...
64
votes
8answers
94k views

Bulk rename, change prefix

How can I bulk replace the prefix for many files? I have a lot of files like TestSRConnectionContext.h TestSRConnectionContext.m I would like to change all them to CLConnectionContext.h ...
62
votes
2answers
156k views

Location of the crontab file

as many (most?) others, I edit my crontab via crontab -e, where I keep all routine operations such as incremental backup, ntpdate, various rsync operations, as well as making my desktop background ...
57
votes
3answers
18k 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///...
53
votes
7answers
115k 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 ...
52
votes
4answers
95k views

What is the maximum allowed filename (and folder) size with eCryptfs?

I am a new eCryptfs user and I have a very basic question that I wasn't able to find anywhere. I am interested in using eCryptfs via my Synology NAS that uses Linux. While trying to encrypt my folder ...
52
votes
1answer
73k 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 ...
52
votes
3answers
45k 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 ...
51
votes
2answers
5k views

Why do some Linux files have a 'd' suffix?

I observed some of the binary files and configuration filenames end with a d. What is reason for putting a d at the end of the file name? Like httpd, ospfd, pppd, syslogd, telnetd, pptpd, inetd, ...
49
votes
16answers
29k 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 ...
48
votes
9answers
140k views

How to list files without directories, and filter by name (ls options)

I have a directory called uploads. It contains a bunch of files, plus a few subdirectories which in turn contain files. Is there a way I can (in one step) do the following: List ONLY the files in ...
47
votes
4answers
18k views

Is the slash (/) part of the name of the Linux root directory?

Is the slash (/) really part of the name of the Linux root directory? Or is it just a symbol for it? What about /etc and so on? Update Suppose /dev/sda2 is the block device of a Linux root ...
44
votes
3answers
16k views

How can I stop seeing hidden files in the Midnight Commander?

The Midnight Commander is a very helpful tool when we're using only the text mode. But sometimes it bothers me that I have to see all the hidden files inside a folder (files that begin with "."). I'...
44
votes
3answers
18k 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 ...
42
votes
8answers
66k 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 ...
38
votes
9answers
101k views

How to list all files in a directory with absolute paths

I need a file (preferably a .list file) which contains the absolute path of every file in a directory. Example dir1: file1.txt file2.txt file3.txt listOfFiles.list: /Users/haddad/dir1/file1.txt /...
38
votes
7answers
26k views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
38
votes
5answers
9k views

Make pwd result in terms of “~”?

pwd gives me /data/users/me/some/random/folder Is there an easy way of obtaining ~/some/random/folder from pwd?
37
votes
7answers
12k views

Is `~/Documents` a relative or an absolute path?

This is merely just a vocabulary question, but which keeps turning around in my head. It comes from a practice exam from a LPIC preparation book. The correct answer according to the book is that ~/...
37
votes
2answers
1k views

Completing avfs fake directories in zsh

How can I tweak zsh's completion system to complete “fake” files in some circumstances? More precisely, the AVFS filesystem exposes archives as directories by creating a “fake directory” next to ...
36
votes
2answers
137k views

How do you put date and time in a file name?

I'm trying to execute a command and would like to put the date and time in the output file name. Here is a sample command I'd like to run. md5sum /etc/mtab > 2016_4_25_10_30_AM.log The date time ...
35
votes
3answers
93k 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 ...
35
votes
4answers
139k views

Is space not allowed in a filename?

It is said that on Unix and Linux in general, you should avoid having spaces in a filename of a file (ordinary file, dir, link, device file, ...). But I do that all the time. For a filename with a ...
35
votes
5answers
115k views

print output to 3 separate columns

MYPATH=/var/www/html/error_logs/ TOTALFILE=$(ls $MYPATH* | wc -l) FILETIME=$(stat --format=%y $MYPATH* | head -5 | cut -d'.' -f1) FILE=$(ls -1tcr $MYPATH* | head -5 | rev | cut -d/ -f1 | rev) ...
34
votes
6answers
66k views

adding text to filename before extension

I would like to add text to the end of filename but before the extension. Right now I am trying, for f in *.shp; do echo $f_poly; done the output is, Quercus_acutifolia.shp_poly Quercus_agrifolia....
33
votes
5answers
9k 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 ...
32
votes
5answers
6k views

Vim: what are all the possible swapfile extensions?

When you're editing a file in vim, it generates a swapfile with the same name as your current file, but with a .swp extension. If .swp is already taken, then it generates one a .swo one. If that's ...
32
votes
1answer
6k views

Why can Linux show a file name containing character '/'?

The following picture is snapped in a real Linux environment. Why can Linux show a file name containing character '/'?
32
votes
2answers
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 ...
32
votes
2answers
2k views

find(1): how is the star wildcard implemented for it to fail on some filenames?

In a file system where filenames are in UTF-8, I have a file with a faulty name; it is displayed as: D�sinstaller, actual name according to zsh: D$'\351'sinstaller, Latin1 for Désinstaller, itself a ...
31
votes
1answer
11k 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?
30
votes
7answers
35k views

Is it considered a best practice to not use capital letters in file naming?

People say you shouldn't use spaces in Unix file naming. Are there good reasons to not use capital letters in file names (i.e., File_Name.txt vs. file_name.txt)? Or is this just a matter of personal ...
30
votes
1answer
12k views

For filenames, are underscores or dashes more common in Unix file names? [closed]

When you are naming files with multiple words in the name, is it more common in Unix systems to use underscores, camel case, or dashes to separate the words?
29
votes
3answers
4k views

Is it part of any standard (e.g. POSIX), that system files should be lower case?

My company resells an application whose brand name is mixed case, for example "ApplicationName". The application's installer creates all paths and file names in this standard. E.g. The main directory ...
29
votes
10answers
3k views

Dealing with file names with special first characters (ex. ♫)

I have recently come across a file whose name begins with the character '♫'. I wanted to copy this file, feed it into ffmpeg, and reference it in various other ways in the terminal. I usually auto-...
29
votes
2answers
2k views

Is it true that a tarball can change where files are extracted to regardless of the commands used to extract it?

I have a coworker who says you need to be careful extracting tarballs because they can make changes you don't know about. I always thought a tarball was just a hierarchy of compressed files, so if you ...
29
votes
2answers
46k 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:...
28
votes
2answers
32k 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.
28
votes
4answers
26k views

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

In a directory size 80GB with approximately 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 ...
28
votes
2answers
26k views

How to zip directory with encryption for file names?

Using command line, I know that I can encrypt a directory with the following command: zip -er Directory.zip /path/to/directory However, this does not encrypt the filenames themselves. If someone ...

1
2 3 4 5
22