Tag Info

Hot answers tagged

59

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


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


37

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


31

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


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


25

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


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

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


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


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


17

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


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

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


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

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


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

The relevant lines in shellcheck's source code are: checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "dirname" = style id "Use parameter expansion instead, such as ${var%/*}." checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "basename" = style id "Use parameter expansion instead, such as ${var##*/}." ...


13

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


13

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


13

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


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

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


13

This directory is called the root directory and is referenced by the symbol "/" You can try cd / to go there. Notice that if you try this: $ cd / $ cd .. You're still at the root directory. NB: Every Unix system has a super user account called root, whose home directory is /root. I know it's redundant, it can be ambiguous and lead to confusion. So ...


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


12

Full disclosure: I am one of the authors and the current maintainer of the eCryptfs userspace utilities. Great question! Linux has a maximum filename length of 255 characters for most filesystems (including EXT4), and a maximum path of 4096 characters. eCryptfs is a layered filesystem. It stacks on top of another filesystem such as EXT4, which is ...


11

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


11

When writing a paper, I often collect a bibliography of PDF files from various sources. Not all of these contain the correct metadata, which means I sometimes copy-paste the title of the paper from the PDF viewer into the filename. This often results in newlines within the file name, but has never been an issue with any tools I have used. IMHO there is ...


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.



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