Tag Info

Hot answers tagged

5

You don't need to loop, you can tell cat to read all the files: cat /var/abc/*.csv > file1.csv && rm /var/abc/*.csv as long as there aren't too many files (but the limit is huge). Using && between the two commands ensures the files are only deleted if they were successfully "copied". There are a couple of caveats though: you mustn't ...


5

Pass the -o and -g options to omit the user and group columns. Since user and group names can contain spaces, you can't reliably edit them out. There's no option to omit the permissions and link count columns. Since the first column you want to keep can start with whitespace (for right alignment), you can't use the whitespace-to-non-whitespace transition as ...


4

From man ls: -a, --all do not ignore entries starting with . -F, --classify append indicator (one of */=>@|) to entries -h, --human-readable with -l, print sizes in human readable format (e.g., 1K 234M 2G) -l use a long listing format The command ls -alhF is equivalent to ls -a -l -h -F The ability to ...


2

As POSIX define, ls will output one entry per line if output is not a terminal, or one of -C, -m, -x was used. When output is terminal, the output format is implementation-defined. OSX ls and FreeBSD ls use -1 as default option when output is not to a terminal


2

For this sort of task, I like to break out the perl. There's a module called File::Find which is core, that is quite good for this: #!/usr/bin/perl use strict; use warnings; use File::Find; my %found; sub collate_users { next if -d; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ...


2

Here's a slightly shorter version that uses find: find <path> -printf "%u\n" | sort -u Depending on the complexity of the directory structure, this may or may not be more efficient.


2

The argument to a LS_COLORS directive is a string that is written to the terminal as part of an escape sequence. When displaying a file name, ls writes \e[, then the string associated with the file type, then m, then the file name, then \e[0m (where \e represents an escape character). This is the escape sequence that tells xterm and compatible terminals ...


1

Your command looks almost fine. Just add a cat and >> to actually append the content: for i in /var/abc/*.csv; do cat "$i" >> file1.csv && rm -rf "$i";done I don't quite understand the counting part. You could do something like this: let count=0 for i in /var/abc/*.csv; do cat "$i" >> file1.csv && rm -rf "$i" let ...


1

This works for me: ls -lhn | sed -r 's#^\S+(\s+\S+){3}##' The extra -n flag to ls turns user and group names into numeric ids. As a result we get a known number of fields to strip: -rwxr-xr-x 1 1001 1001 1.4K Mar 23 18:07 something.sh The whitespace between each of the columns is variable but is what ls uses to align columns, so we cannot just blindly ...


1

When you type C-a l, this runs ls and displays the output in the current window, regardless of what program is running in the window. If you do this with a shell running in the window and the shell is displaying its prompt, then the output of ls is displayed after the prompt. The shell is not aware of what happened, since ls is executed directly by Screen. ...


1

That is because the output of your ls command is just the list of file names, not their path. The truncate command will, therefore, recreate the same file names as empty files in the current directory. In addition, your approach, even if done correctly, will break on even slightly strange filenames (those that contain a space, for example), let alone more ...


1

You can use piped I/O from a command in awk (at least gawk, I haven't tested this on Solaris): find . -type f | xargs ls -l | awk 'BEGIN { OFS="\t" } { command=sprintf("file \"%s\"", $9); command | getline type; close(command); print type, $3, $4 }' | tr ":" "\t" If your find supports it you can simplify this with find . -type f -ls | awk ... There's a ...


1

find . ! -name . -prune -print | grep -c / Should be fairly portable to post-80s systems. That counts all the directory entries except . and .. in the current directory. To count files in subdirectories as well: find .//. ! -name . | grep -c // (that one should be portable even to Unix V6 (1975), since it doesn't need -prune)



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