Tag Info

New answers tagged

0

This version has some additional information and doesn't color the entire lines: eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e ...


1

The most likely scenario is that you accidentally gave all files in the directory execute permission.


2

The command you have above will (somewhat clumsily) rename all files in the current directly from *.jpg to *.jpeg, it could be modified to delete all files but is hardly appropriate to the task. However, it sounds like you are trying to craft a suitable filename such that when the above command encounters it, it will delete everything in the current ...


0

I think you want to search for those files that start with data and then following by any three character (XXX) which is ends with .csv, right? So you can use grep with find command: find . -maxdepth 1 -type f -printf "%f\n" |grep -c '^data...\.csv$' . refer to current directory. -maxdepth 1 looking for files only in current directory(maximum 1 level). ...


0

Using find to test that they are a file (-type f) and match the required pattern ("data*.csv"): find directory/ -type f -name "data*.csv" | wc -l


0

There are probably fancier ways, but what works for me is ls /directory/data* | wc -l


1

With a GNU ls at least (and, apparently, tcsh's implementation) you can hack the $LS_COLORS environment variable to insert delimiters where you like (but tcsh's builtin ls-F doesn't do link targets - only link flags) Usually ls inserts arbitrary non-printable terminal escapes based on the values stored within that environment var, but there's nothing ...


3

ls unfortunately doesn't have an option to retrieve file attributes and display them in an arbitrary way. Some systems have separate commands for that (for instance GNU has a stat command or the functionality in GNU find). On most modern systems, with most files, this should work though: $ ln -s '/foo/bar -> baz' the-file $ LC_ALL=C ls -ldn the-file | ...


4

Use the file command. [sreeraj@server ~]$ ls -l mytest lrwxrwxrwx 1 sreeraj sreeraj 15 Dec 12 09:31 mytest -> /usr/sbin/httpd [sreeraj@server ~]$ file mytest mytest: symbolic link to `/usr/sbin/httpd' or [sreeraj@server ~]$ file -b mytest symbolic link to `/usr/sbin/httpd' [sreeraj@server ~]$ Also, please go read through man page of ls and check ...


3

Assuming file names don't contain newline characters and don't start with ., this should work: ls -d -- *.sas | grep -v '^qc_d[ltf]' List files ending in .sas and filtering all that is NOT qc_dl, qc_dt, qc_df For any filtering needs, grep is your friend.


7

Use find instead? find /my/example/dir -type f -name '*.sas' ! -name 'qc_d[ltf]*'


8

From man bash: If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Composite patterns may be formed using one or more of the following sub-patterns: ?(pattern-list) ...


-1

for i in *; do echo $i; ls $i | wc -l; done


-2

Try this ls -l | awk '{$5=sprintf("%.9f GB", $5/1024^3)} 1'


0

Both commands redirect output of ls command to file with name list. > will create/replace the output file with name list. >> will create (if file list not exists already) or append the file list. Can see the contents of file list using cat list.


0

This: ls > list means redirect the output from the ls command to a new file called list. If the file already exists, replace it. Whereas ls >> list means redirect the output from the ls command and append it to the file called list If the file doesn't exist create it.


2

Both redirect stdout to file. ls > list If file exists it'll be replaced. ls >> list If file not exists it'll be created. If it exists, it'll be appended to the end of file. Find out more: IO Redirection


1

You don't really want to do this in bash, but because you asked, this is how you could split it up. #!/bin/bash re='^[0-9]+$' for x in `/usr/bin/ls -l --time-style=+'%s' /var/indexes | sort -k3,3 | awk '{print $3 $7}'` do read -A nm <<< "$x" if [[ ${nm[0]} =~ $re ]] ; then echo "found one " ${nm[1]} fi done It's easier in awk like so: ...


3

Wouldn't it be easier to use find with the -nogroup flag? For example: find /var/indexes -nogroup If you want to base the script around ls then awk is tool I'd use to select columns.


0

on many derivatives you can also simply use (as on DOS): dir it will show the results without color, you can add the arguments same to ls, like -l


0

If you want to save foldename as csv file use this command: ~/test$ ls -d */|tr -d '/'| paste -sd , > outfile.csv dir1,dir2,dir3 ls -d */: list all directory names in current directory(in my case current directory is /home/KasiyA/test/). tr -d '/': removes / at the end of each name of directories. paste -sd ,: paste the result of previous tr command ...


-1

Try this: ls -ld */ | awk -v OFS="," 'NR>1{print $3,$4,$5,$6" "$7,$8,$9}' > output.csv Include only the column numbers you want in the {print .....} block. EDIT: Play around with the coloumn numbers to arrange the coloumns in the order you wish to.


0

If you want folder names, do: find . -maxdepth 1 -mindepth 1 -type d -printf '%P,' | sed 's/,$/\n/' > output.csv Parsing the output of ls is bad idea. find can be used in combination with other tools to emulate the output of ls in many cases, and is a better tool for the job. -maxdepth 1, -mindepth 1: find will usually recursively search inside any ...


1

Another alternative (piping two tr commands): ls -l partition | cut -c5-7 | tr -dc rwx | tr rwx cse


2

Alternative way without ls: getfacl -c partition | sed -n '/group::/{s/.*:://;y/rwx/cse/;s/-//g;p;}'


3

I think you want this command: ls -l partition | cut -c5-7 | tr rwx cse |sed 's/-//' You can remove the one extra command(cut -d ' ' -f 1) and replace it with your last cut command(cut -c5-7) and also add sed 's/-//' at the end to remove all -s. Now you are done. you didn't need to adding extra |. And even better: you can also change the dash(- ...



Top 50 recent answers are included