Hot answers tagged filenames
54
Multiple slashes are allowed and are equivalent to a single slash. From the Single Unix specification (version 3), base definitions §3.266 pathname: “Multiple successive slashes are considered to be the same as one slash.”
There is one exception: if a pathname starts with exactly two slashes, it may be treated differently (ref: base definitions §4.11 ...
54
They are daemons (Computing) – as in "workers behind the curtain".
http Daemon - Hypertext Transfer Protocol Daemon
ospf Daemon - Open Shortest Path First Daemon (89)
ppp Daemon - Point-to-Point Protocol Daemon
syslog Daemon - Syslog Daemon
telnet Daemon - Telnet server Daemon
pptp Daemon - Point-to-Point Tunneling Protocol Daemon
dhcp Daemon - ...
32
Short answer (closest to your answer, but handles spaces)
OIFS="$IFS"
IFS=$'\n'
for file in `find . -type f -name "*.csv"`
do
echo "file = $file"
diff "$file" "/some/other/path/$file"
read line
done
IFS="$OIFS"
Better answer (also handles wildcards and newlines in file names)
find . -type f -name "*.csv" -print0 | while IFS= read -r -d ...
30
In this case, it means ‘standard input’. It's used by some software (e.g. tar) when a file argument is required and you need to use stdin instead. It's not a shell construct and it depends on the program you're using. Check the manpage if in doubt!
In this instance, standard input is the argument to the -f option. In cases where - isn't supported, you can ...
24
For the most part, repeated slahes in a path are equivalent to a single slash. This behavior is mandated by POSIX and most applications follow suit. The exception is that “a pathname that begins with two successive slashes may be interpreted in an implementation-defined manner” (but ///foo is equivalent to /foo).
Most unices don't do anything special with ...
23
The file has a name, but it's made of non-printable characters. If you use bash, you can try to remove it by specifying its non-printable name. First ensure that the name is right with: ls -l $'\177'
If it shows the right file, then use rm: rm $'\177'
Another (a bit more risky) approach is to use rm -i -- * . With the -i option rm requires confirmation ...
20
You can use the readlink utility, with the -f option:
-f, --canonicalize
canonicalize by following every symlink in every component of
the given name recursively; all but the last component must
exist
Some distributions also come with a realpath(1) utility that basically just calls realpath(3) and does pretty much the same ...
19
It's basically removing backup files.
*~ means all files ending in ~.
Many Unix/Linux systems programs create backup files that end in ~.
For example, the emacs and nano editors automatically save a backup copy of each file you edit. When it saves a file, the old version gets saved using the file name with a tilde (~) added to the end.
Vim will do the ...
15
As noted by others, there isn't really an answer to this: filenames and paths do not have an encoding; the OS only deals with sequence of bytes. Individual applications may choose to interpret them as being encoded in some way, but this varies.
Specifically, Glib (used by Gtk+ apps) assumes that all file names are UTF-8 encoded, regardless of the user's ...
15
In Unix, almost everything is a file. A directory is a special type of file that from the user's perspective can "contain" other files.
The error Not a directory occurs because your existing file is not a directory, and since a directory is a type of file, and there cannot be two identically named files in one directory, the operation cannot be performed.
14
You are removing a file with an & character in the name, and the rm command is being put in the background. (For the record, the 1 is the job number, and the 12345 is the process ID)
It is important to quote or escape any filenames that contain special characters. A good rule of thumb is: if you think something might be a special character, it can't ...
13
Originally, on unix systems, the extensions on file names were a matter of convention. They allowed a human being to choose the right program to open a file. The modern convention is to use extensions in most cases; common exceptions are:
Only regular files have an extension, not directories or device names. The mere fact of being a directory or device is ...
13
From the POSIX Specification:
A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.
I assume Linux bash keeps this behavior in case there's a compelling future use.
(I've always heard that Al Viro kept it in place because ...
13
find will look through a directory structure and return results based on a glob:
find /your/dir -name "*abcde*"
Adding the -type f switch will refine your search criteria to only return files.
find /your/dir -type f -name "*abcde*"
You could also include other switches like -maxdepth 2 to restrict the search to 2 levels of directories bellow the ...
12
The OS doesn't appear to care about it either, having just tried out a C program with a direct syscall to open with a // in the path.
You can use the python library function os.path.normpath to normalize it though, which saves you having to scan through the string looking for extras. Other languages have similar functions.
...
12
Every program can see the full command line that was used to run it (except for wildcards and variables, which the shell expands).
In a C program, the command line is stored in argv, which is short for argument vector.
The progam's name is the first element of argv, i.e. argv[0].
Clearly in the case of halt and reboot, the program is changing its behavior ...
11
I guess you see this � invalid character because the name contains a byte sequence that isn't valid UTF-8. File names on typical unix filesystems (including yours) are byte strings, and it's up to applications to decide on what encoding to use. Nowadays, there is a trend to use UTF-8, but it's not universal, especially in locales that could never live with ...
11
It's because the caret is often used to signify the ctrl key having been pressed, or that it's otherwise a control character.
The key sequence that you actually typed was this:
cp filename.xsl .ctrl+Vbackspace~Enter
You were presumably trying to copy the file to your home directory (~). You can repeat this by typing ctrl+Vbackspace. You'll see ^? printed ...
11
for file in * ; do
echo mv -v "$file" "${file#*_}"
done
run this to satisfy that everything is ok.
if it is, remove echo from command and it will rename files as you want.
"${file#*_}"
is a usual substitution feature in the shell. It removes all chars before the first _ symbol (including the symbol itself). For more details look here.
11
A filename may not be empty. To quote the Single Unix Specification, §3.170, a filename is:
A name consisting of 1 to {NAME_MAX} bytes used to name a file. The
characters composing the name may be selected from the set of all
character values excluding the <slash> character and the null byte.
So, it must consist of at least 1 byte, i.e., not ...
10
I've never seen a file name with a newline other than ones deliberately created to test applications that manipulate file names. File names containing newlines can appear because:
Some bug or user error (e.g. a bad copy-paste) resulted in an unintended file name.
Some filesystem corruption affected a file name.
Someone deliberately created a “strange” file ...
9
This script fails if any file name contains spaces or shell globbing characters \[?*. The find command outputs one file name per line. Then the command substitution `find …` is evaluated by the shell as follows:
Execute the find command, grab its output.
Split the find output into separate words. Any whitespace character is a word separator.
For each word, ...
9
This sounds like a job for find.
Use -maxdepth to only return the current directory, not recursivly search inside subfolders
Use -type f to only return files and not directories or device nodes or whatever else
Use a combination if -not and -name to avoid the files with names you don't want
It might come together like this:
find /path/to/uploads ...
9
GNU ls (i.e. the ls command on non-embedded Linux systems and Cygwin, also available on some other unices) has an option to hide some files, based on their names. There's no way to ignore directories though.
ls --hide='t_*' uploads
Another approach is to make your shell do the matching. Bash, ksh and zsh have a negation pattern !(t_*) to match all files ...
9
Every directory on a Unix system (and probably every other system too) contains at least two directory entries. These are . (current directory) and .. (parent directory). In the case of the root directory, these point to the same place, but with any other directory, they are different. You can see this for yourself using the stat, pwd and cd commands (on ...
8
If there are a lot of matches to using a wildcard with rm like rm -i ?, you can always remove it by inode number instead:
ls -i
find . -inum <inode> -ok rm '{}' \;
Where <inode> is the inode number from ls -i, which lists all the inode numbers of the files in the current directory.
8
In unix filename is just a string, unlike DOS, where filename was composed from name and extension. So any of given filenames is completely acceptable.
But many programs still use file suffixes beginning with dot to distinguish different file types, i.e. Apache Web Server uses suffixes to set correct MIME type in answer headers.
8
According to the POSIX definition, paths starting with a double-slash (//) "...may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash." If you use csh, for example, it doesn't act the same way:
% bash -c 'cd //; pwd'
//
% csh -c 'cd //; pwd'
/
Bash appears to be storing the ...
Only top voted, non community-wiki answers of a minimum length are eligible
