Tag Info

Hot answers tagged

68

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 ...


57

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 ...


56

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 - ...


45

You can't rename a file to . or .. because all directories already contain entries for those two names. (Those entries point to directories, and you can't rename a file to a directory.) mv detects the case where the destination is an existing directory, and interprets it as a request to move the file into that directory (using its current name). ...


38

$ touch ./-c $'a\n12\tb' foo $ du -hs * 0 a 12 b 0 foo 0 total As you can see, the -c file was taken as an option to du and is not reported (and you see the total line because of du -c). Also, the file called a\n12\tb is making us think that there are files called a and b. $ du -hs -- * 0 a 12 b 0 -c 0 foo ...


35

Why not to use built-in ls feature for this particular case, namely -v natural sort of (version) numbers within text For example ls -1v log*


34

Either quote it: rm -i '~' rm -i "~" rm -i \~ Or reference it by a path, instead of just a basename: rm -i ./~ rm -i /path/to/~ Note that, despite being a funny-looking single character name, this is conceptually no different than if you had created a file named SOME$PATH by doing touch 'SOME$PATH' And tried to remove it by doing: rm -i SOME$PATH ...


33

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 ...


28

Spaces, and indeed every character except / and NUL, are allowed in filenames. The recommendation to not use spaces in filenames comes from the danger that they might be misinterpreted by software that poorly supports them. Arguably, such software is buggy. But also arguably, programming languages like shell scripting make it all too easy to write software ...


27

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 ...


26

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 ...


26

Maybe they only look like they have the same name. Try: $ touch Stéphane Stéphane Stéphane\ St​éphane $ ls -1 Stéphane Stéphane St​éphane Stéphane They look pretty much the same. $ ls -1b Stéphane Stéphane St​éphane Stéphane\ Slightly better. The space character is flagged as \ (though not all ls implementations do that). $ LC_ALL=C ls -1b ...


25

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 ...


22

Far more important that a particular convention is being consistent. Pick a style, and stick with it.


22

It's not about efficiency, it's about correctness. basename uses newlines to delimit the filenames it prints out. In the usual case when you only pass one filename, it adds a trailing newline to its output. Since filenames may contain newlines themselves, this makes it difficult to correctly handle these filenames. It's further complicated by the fact that ...


21

You're probably confused because these files don't have extensions (endings like .txt), which are essential to determine a file's content on Windows. On Linux, most programs don't rely on a file's extension to determine which program to open it with, but instead look at its first few bytes (the "magic bytes") that usually reveal the file's type. Due to ...


20

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 ...


20

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 ...


19

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 ...


18

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 ...


17

Bash, ksh and zsh have better solutions, but in this answer I assume a POSIX shell. The pattern .[!.]* matches all files that begin with a dot followed by a non-dot character. (Note that [^.] is supported by some shells but not all, the portable syntax for character set complement in wildcard patterns is [!.].) It therefore excludes . and .., but also files ...


16

bash's braces, {}, will enumerate them in order: for file in log{1..164}.gz; do process "$file" done


16

.. is not special, it is just that it already exists. On Unix, Dos and MS-Windows every directory has a directory . it links back to itself, and a directory .. it links to its parent directory (or self if root directory). If .. and . are special it is only because you can not remove them (actually you can, you just remove the directory that contains ...


15

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 ...


15

. is used to separate a filetype extension, e.g. foo.txt. - or _ is used to separate logical words, e.g. my-big-file.txt or sometimes my_big_file.txt. - is better because you don't have to press the Shift key, others prefer _ because it looks more like a space. So if I understand your example, backup-part2-random or backup_part2_random would be closest to ...


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

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, ...


14

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 ...


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 ...


14

For those who use vim run it in the current working directory: $ vim ./ and navigate to the file with the arrow keys or j/k. Then hit Shift+D and confirm deletion with y.



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