Tag Info

Hot answers tagged

20

You either have trailing whitespace, or a corrupt filesystem. Try for i in tftp.plist* do echo "'$i'" done That should output something like 'tftp.plist' 'tftp.plist ' note the quotes and the extra space. If it outputs the exact same thing twice, you likely have a corrupt filesystem. Try ls -i tftp.plist* this will give you the inode numbers ...


9

Note the . at the end of the permissions (drwxrwxrwx.): that means there's an SELinux context involved. You need to get that right for your user to be able to list the contents of the directory. To see the contexts for your directory, run sudo ls -alZ (the -Z option shows the SELinux contexts required). The CentOS wiki has a good page on SELinux. You'll ...


6

ls has different output formats and displays things differently if it's writing to a terminal instead of a pipe. When writing to a pipe it writes just one entry per line, so grep can work on each listing individually. So when you do that grep you are getting a different output from ls than when you just run ls and print to the screen. You can see the same ...


5

You can use -o for logical OR. Beware however that all find predicates have logical values, so you'll usually need to group ORed things together with parens. And since parens also have a meaning to the shell, you'll also need to escape them: find /some/dir -maxdepth 1 \( -name '*.c' -o -name '*.h' \) -print


4

The permissions you got were the permissions you asked for. The 't' comes from the '1' in the '1775' permissions string you specified, and sets what is called the "sticky bit". This tells the system that files in that directory can only be renamed or removed by the file's owner, the directory's owner, or the root user. The get the permissions you wanted ...


4

For files which are not device that is not the minor number but the size in bytes. The size of a directory depends on which filesystem is used, and how many entries (i.e. files or subdirectories) are in it.


4

If you use ksh (or bash with extended globbing activated, or zsh with ksh globs enabled) you can achieve the desired function using only file globbing patterns: ls -d -- !(*bak) With grep, to get a simple solution, just use the negation -v: ls | grep -v 'bak$'


3

printf %c,\\n * | sort -fu | dd cbs=8 conv=lcase,block ...will... print the first character of every argument matched in the * glob followed by a comma and a \newline to stdout sort that stream while ignoring case and squeezing duplicates fold that stream into a single line of 8 (space-padded) chars per record while simultaneously converting all ...


3

Just for the record; a shell only solution with ksh (ksh93 required here) or (newer versions of) bash if all the external processes shall be avoided: typeset -A a for file in * do typeset -l f=${file:0:1} ; a+=( [$f]= ) done list=$( printf ", %s" "${!a[@]}" ) printf "%s" "${list#, }"


3

You could do it with the shell/coreutils: for f in *; do printf "%s\n" "${f:0:1}" ; done | tr '[A-Z]' '[a-z]' | sort | uniq | paste -d, -s The ${var:X:Y} syntax prints a Y-character long substring of variable $var starting at position X


3

You can go with ls -1 | cut -b1 | tr '[:upper:]' '[:lower:]' | sort -u | paste -d, -s where: ls -1 gives you a list of filenames (one per line), cut -b1 takes just the first char per line, tr '[:upper:]' '[:lower:]' turns all to lower cap, sort -u removes the duplicate, and paste -d, -s puts the lines together using , as a separator.


3

Using find: find . -maxdepth 1 -type f ! -name "*bak" .: asserts to search in the current working directory -maxdepth 1: asserts to search only one level below the specified directory (i.e. only the current working directory) -type f: asserts to search only for files ! -name "*bak": asserts to search only for filenames not ending in bak However, if you ...


3

Regular languages (i.e. "this can be matched with a RE") are closed under complement, so it's possible, but it's not very useful for practical purposes: what you start out with is the condition last letter is k AND letter before that is a AND letter before that is b (let me write s[-1]=='k' and s[-2]=='a' and s[-3]=='b' in a pythonesque fashion) so a ...


3

The POSIX standard says: "Filenames beginning with a ( '.' ) and any associated information shall not be written out unless explicitly referenced, the -A or -a option is supplied, or an implementation-defined condition causes them to be written." Being root is evidently not considered a condition which causes hidden files to be written by the GNU ...


2

Those are not minor numbers (as they are for the device nodes). This answer explains each field in turn.


2

To answer your question, you can use -o option: expr1 -o expr2 Or; expr2 is not evaluated if expr1 is true. expr1 -or expr2 Same as expr1 -o expr2, but not POSIX compliant. like this: $ find . -maxdepth 1 -name "name1" -o -name "name2" ./name1 ./name2


2

The default regex type for GNU find is emacs, which doesn't support intervals. You can specify different regex types, such as posix-egrep, which will solve your issue: find . -maxdepth 1 -type d -regextype posix-egrep -regex './[0-9]{6}'


1

A shell alias is used as an interactive part of the shell. When you call sudo you leave the shell and execute a command. You could either enter an interactive shell with sudo -s, define your aliases and use them, or you have to rewrite your aliases as commands or functions, for example use a folder /root/alias-cmds and write the command /root/alias-cmds/ll: ...


1

With POSIX BREs that have no alternation operator, you can use that \{0,1\} instead: LC_ALL=C grep '^\.\{0,2\}\(.*[^k]\)\{0,1\}\(.*[^a].\)\{0,1\}\(.*[^b]..\)\{0,1\}$'


1

Getting the creation date will be a tough one on a Linux system as it isn't stored. Related question: How to find creation date of file? Use the ls command to list files, try the options -a and -s to list all, and list their sizes. Use the command man ls on the command line to read a full description on the ls command


1

Here's an answer to question Y (ignoring question X), inspired by the OP's attempt: #!/bin/sh while read ls_out do extra=0 perms=0 for i in {1..9} do # Shift $perms to the left one bit, so we can always just add the LSB. let $((perms*=2)) this_char=${ls_out:i:1} ...



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