Tag Info

Hot answers tagged

5

Without / it might also be a file. In some situations it can be deadly. For example when using mv: mv file1 mydirectory mv file2 mydirectory mv file3 mydirectory All right? But if mydirectory did not exist or wasn't a directory, the final result is that file1 and file2 are gone and file3 is now named mydirectory. mv file1 mydirectory/ mv file2 ...


5

Using GNU find: find /some/path -type f -printf '%f\n' | sort | uniq -c Using POSIX find: find /some/path -type f | sed 's~^.*/~~' | sort | uniq -c This assumes your filenames don't contain newlines.


4

In bash, this will delete everything in the current working directory which has the prefix ._: rm ._* If what you actually wanted to do was change their names to a form without the prefix, you can run: ls ._* | while read line do mv -- "$line" "${line:2}" done


4

Make sure you are typing in /usr/bin, not usr/bin. The latter means "look for usr/bin starting in the current directory." For example, if your current directory is your home directory (~), then it will look for ~/usr/bin. The former means "look for /usr/bin starting from the root directory." This makes sure that the search for usr/bin starts from the root ...


4

It would be a rare situation indeed where you actually need to store a string (in a variable) along with leading and trailing quotation marks which aren't part of the data. It is typically better to post-process. var='two spaces' printf '# "%s"\n' "$var" # "two spaces" ary=( 'two spaces' '$USER' ) printf '# "%s"\n' "${ary[@]}" # "two spaces" # ...


3

Get the file size: size="$(stat --printf="%s" "$path")" Get the path without the last extension: path_without_extension="${path%.*}" Compare the two: [ "${path_without_extension}.${size}" = "$path" ]


2

I don't think you want the quotes. I think you just don't want to split into fields on whitespace that isn't newlines. Here's how to do that: http://stackoverflow.com/questions/11393817/bash-read-lines-in-file-into-an-array And here's an example $ IFS=$'\n' read -d '' -r -a FOUNDFILES < <(echo -e "very very latest\nsome other line") $ echo ...


1

That would likely be a "display" thing with ls, i.e., if you do ls -p or ls -F (assuming GNU ls), it should consistently add the slash after directories. It's essentially adding visual cues as to what it thinks the file is. (Do note that -F will also, e.g., append @ to symlinks, * to files with executable permissions, | to named pipes, = to sockets and so ...


1

You can also look into readlinkat(..), it handles more error scenario's than readlink(..)


1

It is operating system specific. On Linux and POSIX, consider readlink & readlinkat & lstat (and stat for symlinks without existing targets) & symlink & unlink ... Maybe realpath(3) & access(2) & faccessat & basename(3) might be helpful to you. Perhaps POCO & Glib/GObject/GIO from GTK are offering wrappers working on both ...



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