Tag Info

New answers tagged

2

mv folder to .newfolder - .mvfolder, the dot in front hides the files. Try ls -la - its on the same level as your folder, probably.


0

My guess is that you edited your script on Windows at some point, and that version had Windows line endings: a CR (carriage return) followed by a LF (line feed). As far as Unix shells are converned, LF is the line ending character, and CR is an ordinary character. So if you have this in your script (where ␍ is a CR character): mkdir -p ...


2

If I had to hazard a guess I'd be suspicious of the files and whether they have non-printable characters in their names. You can display these special characters through the use of the following switches to ls. excerpt from Removing Non-printing Characters from File Names Locating "non-printing" characters in file names The ls command has all the options ...


5

ls ends each filename with a newline (\n) and not a NUL (\0) (if its standard output is not a terminal). A way to list the files in the current directory, using NUL as a separator, is: find . -maxdepth 1 -print0. This will match the files starting with a period too. To ignore them, use: find . -maxdepth 1 \! -name '.*' -print0 Others ways could be: ls ...


2

From the manual: -I pattern, --ignore=pattern In directories, ignore files whose names match the shell pattern (not regular expression) pattern. As in the shell, an initial . in a file name does not match a wildcard at the start of pattern. Sometimes it is useful to give this option several times. For example, $ ls --ignore='.??*' ...


0

It uses POSIX.2 regex pattern format. See the re_format(7) man page for specific details.


1

You will have to pipe your ls output. Programs like sed or cut can sort out data as long as you know what your delimiter is. Most often in column spacing your delimiter is a tab. However I don't know of many ways or reasons that you would want to split your ls output into columns. You can always pipe your output to 'more' and it will make your data easier ...


1

This is less about the number of columns and more about what shall be output. You cannot configure all the fields but you can hide owner and group by -g and -G and configure the time by --time-style=.


4

No. ls does not have this capability (and few would want it to).


0

"Preserve across reboots", I doubt it. But you can trivially rebuild the cache on booting, which accomplishes almost the same thing minus a small delay. Create a file /etc/cron.d/rebuild-fs-cache and put the following in it: @reboot root /usr/bin/nice -n 19 /usr/bin/ionice -c 3 -t /usr/bin/find / >/dev/null 2>&1 This uses nice and ionice (which ...


4

You can use vmtouch to add files to your page cache (disk cache). Put nohup vmtouch -dl <files or directories> & in your /etc/rc.local file to add and lock files into your page cache on boot. If you want to add files to your page cache, but don't want to lock them into memory, use the -t flag instead of the -ld flags. For more information on the ...


6

Sorting problems can be avoided by explicitly forcing applications to use a certain sort order. You can check the current locale by running locale instead of the program in question and compare the output of different call situations. The sort order can be forced by setting LC_COLLATE / LC_ALL within the command line: LC_COLLATE=C ls ... LC_ALL=C ls ...


3

With zsh: stat -c '%y %n' -- **/*~path/to/ignore/*(D.Om)


6

You don't need that extra ls -tr. This is equivalent to your command and faster: find . -type f | xargs stat --printf="%y %n\n" | sort -n Something like this will exclude a subdirectory of files: find . -type f ! -path './directory/to/ignore/*' \ | xargs stat --printf="%y %n\n" \ | sort -n This will still check every file, if you want to ...


1

The easiest way by far is to use zsh. The glob qualifier om sorts matches in reverse chronological order; use Om for chronological order. for x in /path/to/dir/*(Nom); do … The N glob qualifier causes the pattern to expand to an empty list if the directory is empty. Make this *(DNom) to match dot files.


5

"Don't use ls in scripts" is a problem with POSIX ls "only"; for GNU ls see --quoting-style=. GNU sort solves the problem with --zero-terminated. If it must be compatible then you could use find ... -exec for passing one file name at a time to a script which does the escaping. If at least bash is available: start cmd:> testfunc () { echo ...


16

Many programs make use of this technique where there is a single executable that changes its behavior based on how it was executed. There's typically a structure inside the program called a case/switch statement that determines the name the executable was called with and then will call the appropriate functionality for that executable name. That name is ...


0

In Wheezy (Debian 7) I would rather make all colors appear (not just for single command) uncommenting the line force_color_prompt=yes in an user directory and then copying all color-related code from the line starting with # set a fancy prompt down to just before the end of the file. By the way, ~/.bashrc is really well commented. According to it ...


0

use my functions: setColors () { # http://wiki.bash-hackers.org/scripting/terminalcodes set -a which printf >/dev/null 2>&1 && print=printf || print=print # Mandriva doesn't know about printf hide='eval tput civis' show='eval tput cnorm' CLS=$(tput clear) bel=$(tput bel) case ${UNAME} in AIX) # text / foreground N=$(${print} ...


2

With zsh: autoload age ls -ldrt -- **/*(e{age 2013/03/06:13:20:00 2013/05/18:11:00:00}) See: info -f zsh --index-search=age for details. (note that it will be a lot less efficient than Anthon's GNU find solution as it will parse those dates, do 2 lstats for every file and sort the list of files (you can avoid that last part by adding oN to the list of ...


4

You don't need to use touch if you have a recent version of a recent version of GNU find ( >= v4.3.3 ). With that you can do: find /media/WD/backup/osool/olddata/ -newermt 20120101T1200 -not -newermt 20130101T1400 Please note the T between day and hours. If you want to retry using touch to create reference files for -newer: you can put those anywhere ...


2

I also use stat to get a ls-like output but I use a different approach to format the output: I use TAB as a delimiter (allows for easier parsing afterwards, if needed), format the time via stat and finally filter the output with numfmt (included in GNU coreutils >= 8.21 2013-02-14) to get nice file sizes: stat --printf="%A\t%a\t%h\t%U\t%G\t%s\t%.19y\t%n\n" ...


1

This awk code transforms the rights from symbol to digit. But it covers only the normal cases (i.e. at least not sStT): awk '$1 ~ /^[-dsbclp]([-r][-w][-x]){3}[.+]?$/ {for(i=0;i<3;i++) {symbol=substr($1,2+i*3,3); sum=0; if (substr(symbol,1,1) == "r") sum+=4; if (substr(symbol,2,1) == "w") sum+=2; if (substr(symbol,3,1) == "x") sum+=1; ...


3

You can use the stat command and get roughly what you want: $ stat -c '%A %a %h %U %G %s %y %n' * drwxrwxr-x 775 2 saml saml 4096 2013-05-16 22:02:13.230463837 -0400 alsa drwxrwxr-x 775 31 saml saml 4096 2013-03-26 12:09:20.707827127 -0400 apps -rw-rw-r-- 664 1 saml saml 43627 2013-05-18 12:28:32.157583577 -0400 autosave.h2song -rw-rw-r-- 664 1 saml saml ...


1

My version of Solaris doesn't support ls -v (grrr). And the sort solution provided above 1) requires knowledge of the position of digits in the filename, and 2) doesn't handle things like multi-part version numbers. The approach below is Solaris-compatible, doesn't require foreknowledge of the digit positions, and handles version numbers with 2, 3 or 4 ...



Top 50 recent answers are included