New answers tagged

0

Agreeing with @nsg that you cannot do this, it seems that the documentation is lacking. So you can read the source-code for ls, in print_color_indicator, in particular the place where it checks file-suffix, commenting /* Check the file's suffix only if still classified as C_FILE. */ So, no: you cannot fool it by making a directory-name ending with ".jpg"...


0

As I understands it, you can only specify files that ends with a specific pattern, for example *.jpg=01;31 to make jpg-files red. Then of course you can always trick it with something like this *IMG_20150808_202948.jpg=01;31 :)


0

I think this will do what you want. The approach could, I suppose, be applied to as many utilities as you wanted. But I really wouldn't recommend that because it will break your "finger habits" when you move to a new system that you haven't yet tweaked. ls() { [[ 0 == $# ]] && set -- *; /bin/ls -d "$@"; } By extension your alias would then be ...


-1

Here's a shell function that does what you want. You can paste it directly into your terminal or add it to your shell's initialization file (e.g. ~/.bashrc for bash): function dir { if [ -n "$1" ] then ls -lartd "$@" else ls -lartd * fi }


2

As you mentioned in the comment you want to check current date's file in remote directory, you can do that in following manner: FILE=$(ssh -q "$USER"@"$HOST" 'find /home/oracle/SABARISH/logs/sftp -type f -daystart -mtime -1 | wc -l') if test "$FILE" -eq 0; then exit else # do your SFTP stuff here fi from man find : -daystart Measure ...


1

If what you want is a command cmd so that cmd cr* lists cron.daily itself, then that command is ls -d. If that's too much typing, you can define an alias. For example, put this line in your ~/.bashrc: alias l='ls -d' Then running l cr* will display information about cron.daily itself, while ls cr* will list the contents of the directory cron.daily (and of ...


5

You could use find, which (on many platforms) has an -ls option. So you could do find . -maxdepth 1 -name '*' -ls But if it is hard to remember ls -d, you may not find find an improvement.


1

I recommend to use zsh shell for this job: cp *(m-1) /home/oracle/SABARISH/logs/files/ where (m-1) is so called glob qualifier. In this case we select all (*) files modified (m) within (-) last (1) day.


2

You can do something like this: files=$( ls -l --time-style=+%D | grep $(date +%D) | grep -v '^d' | awk '{print $NF}' ) ; for f in $files ; do cp -rf $f /home/oracle/SABARISH/logs/files/ ; done ; sftp {user}@{host}:{remote_dir} <<< 'put /home/oracle/SABARISH/logs/files/*' or similarly: for f in $(ls -l --time-style=+%D | grep $(date +%D) | grep -...


0

You can try the following feed awk the output of ls your superator is the "." and since all your files will have name.png you print the first column: ls | awk -F"." '{print $1}'


-1

File list display in reverse order: ls -lSrh For ascending order: ls -lSh


0

With a perl one-liner (reformatted for readability): perl -e 'opendir($dh, "."); while ( readdir($dh) ) {$count++}; closedir $dh; print "$count\n";' or perl -e 'opendir($dh, "."); @files = readdir($dh); closedir $dh; print $#files+1,"\n";' You can use perl functions that modify arrays like grep or ...


0

It can be also: tree -if </your/path> or 'pwd' as a path


10

You can use the shell's sort order instead (which may not involve the locale's collation order; bash, AT&T ksh, yash, tcsh and zsh give the expected results, mksh and dash don't. fish seems to give a case insensitive order but gives different results when there are non-ASCII characters): ls -dUl -- .* * This gives ls an explicit list of files (and ...


4

You might simply use two separate ls commands: $ ls -dl ..?* .[^.]* 2>/dev/null ; ls -dl * -rw-r--r--. 1 sparhawk sparhawk 0 8 Jun 09:29 .a -rw-r--r--. 1 sparhawk sparhawk 0 8 Jun 09:29 .b -rw-r--r--. 1 sparhawk sparhawk 0 8 Jun 09:29 a -rw-r--r--. 1 sparhawk sparhawk 0 8 Jun 09:29 A -rw-r--r--. 1 sparhawk sparhawk 0 8 Jun 09:29 b -rw-r--r--. 1 ...


-2

You can play with ls command options. Try this: # ls -laXr Where: -l use a long listing format -a, --all do not ignore entries starting with . -X sort alphabetically by entry extension -r, --reverse reverse order while sorting


1

ls -l will display how many files contain the currunt directory and in long format. in total n files +1 line for total X as header. | wc -l counts the total lines that is fed so in total you will have n+1 (lines+(1)header after executing ls -l | wc -l


2

Yes, and also symlinks and sockets. And the first line (there are several questions here about what that number means) will also be counted. But you'll typically only find devices in /dev (with subdirectories) and there's typically very few files there, so I'm wondering if that's really what you want to do. What are you trying to accomplish? Also ls ...


3

No ls -l | wc -l will report the number of lines the ls -l command would give. Roughly the number of files+directories in the current directory plus something for the header.


1

It will show the number of lines output by ls -l which will include everything that has an entry in the current directory, including files (including special files if present), links, and directories.


3

While doing: find /data/code/ -name "*.jar" -exec {} ls \; you are trying the execute the file found (e.g. /data/code/project/shared/build/thirdparty/log4j-1.2.8/commons-logging-1.0.4.jar) with ls as an argument to it, leading to the permission denied error. Just switch the order: find /data/code/ -name "*.jar" -exec ls {} \; GNU find has -ls option ...


0

I tested these command on Linux Debian in the terminal. If your terminal is wide enough, just stating "ls" will give columns but it won't use all the space (width) of the terminal. I made the terminal as wide as the screen and "ls" just produced 4 columns. Problem is if you pipe this into "more" you loose the columns. Next I used "ls -w200" in the ...



Top 50 recent answers are included