Tag Info

New answers tagged

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


3

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


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.


0

since you cannot have files with the same name in the same directory, I assumed you have them in different directories (e.g. folder1/file folder2/file folder1/otherfile folder2/otherfile ) for name in NAME1 NAME2 NAME3 ; do echo -n $name \ \ \ ls */$name | wc -l done If they just have the same prefix (i.e. picture1 picture2 frame1 frame2 ), then ...


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


4

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


0

If you think about directories or folders in the context of a "fancy filename" the folder is still a file but folder is rather a pointer to a container like a file folder in your filing cabinet, so if you denote or use a slash "/" or slash dot "/." it is helpful for a script to know an be sure you don't mean a file rather than a folder. Hope this makes ...


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


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

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


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" ]


-1

ls -l | awk '{print $5}' gives your file size echo file_name | awk -F"." '{print $3}' gives you file size extracted from name. a=`ls -l | awk '{print $5}'` b=`echo file_name | awk -F"." '{print $3}'` if [ $a -eq $b ] then echo "you can do your processing here" fi


2

You could use another character that cannot appear in a file name: / so once you got your list of files you know that paths are separated by two slashes: // (the second being part of the path as each path starts with a slash but doesn't end with one). You could then use your favourite tool to turn the list into NUL separated paths...


2

An easy and portable way is to insert a file with an empty line in the file arguments: # create file with one empty line echo > emptyline.txt # calling sed: sed -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ file1.ldif.template \ emptyline.txt \ file2.ldif.template \ | ... Some shells support also this: sed -e ...


2

Using GNU sed -s (--separate) extension, you can append an empty newline after each filename (line addresses refer to each filename, instead of treating all the input as one longer stream, similar to awk's FNR and NR variables) sed \ -s \ -e '$a\\' \ -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ file1.ldif.template \ ...


0

I don't have access to OSX so this is a wild guess... but you can try other techniques to delete files, rather than relying on the shell's globbing to match. Try: find . -not -type d -print -delete or even find . -not -type d -print | perl -nle 'print; unlink'


13

The answer from @ubaid-ashraf is almost there. The way to specify file with no extension, in ksh would be: cp -- !(*.*) /new/path/ so that any file with dot in file name is skipped. For that to work in bash, you need to enable the extglob option (shopt -s extglob) and the kshglob option in zsh (set -o kshglob).


1

You can use find+grep to get only files that have no extension find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." So your copy command will be cp ` find . -maxdepth 1 -type f | sed 's/^\.\///' | grep -v "\." ` destination_folder


5

You can do something like: cp -- !(*.txt) /path/to/directory The above code will copy all the files without .txt extension. You can also give multiple extension via pipe character. For example: cp -- !(*.txt|*.c|*.py) /path/to/directory


3

It seems that you have made a mistake when editing PATH variable. Backslash character in your PATH output was considered literal, not escaping for space. You need: PATH="/Applications/Racket v6.2/bin:$PATH"; export PATH or: PATH=/Applications/Racket\ v6.2/bin:$PATH; export PATH



Top 50 recent answers are included