Tag Info

New answers tagged

0

For only adding numbers into the file. awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 }' xyp/dep* > "xyzp/area1" For sorting by numbers. ls -1v xyp/dep* | xargs awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 }' > "xyzp/area1" For sorting from minus numbers. ls xyp/dep* | sort -t 'p' -k 3 -n | xargs awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 ...


1

You can use sed to convert all / into \ by following command: sed 's/\//\\/g' Example: $ echo $PWD | sed 's/\//\\/g' \home\pandya Another way is to use tr: tr '/' '\\' By above command, tr convertes all / with\; Example: $ echo $PWD | tr '/' '\\' \home\pandya


3

I'm not entirely sure what you're trying to do but changing the slashes is easy: $ printf '%s\n' "${PWD//\//\\}" \home\terdon This is using ksh's string manipulation capabilities also available in bash. Specifically, ${foo//bar/baz/} will replace all occurrences of the string bar with baz in the variable $foo. Since / and \ are special characters, they ...


1

This kind of behavior is configured through styles (except for a few fundamentals that have options). You'll want to turn off path-completion. By default, filename completion examines all components of a path to see if there are completions of that component. For example, /u/b/z can be completed to /usr/bin/zsh. Explicitly setting this style to false ...


1

One of the fundamentals of using regex is that patterns are greedy by nature when specifying the wild card. While the answer proposed by @uloBasEI is certainly a working answer, it also requires the use of the basename command. The original question from @Shixons requests a solution using only sed. Before continuing, it's always helpful to know which ...


1

These appear to be files that Qt creates during the course of Inter-process communication. The file names indicate that shared memory and semaphores were used.


4

In general, the empty string does not denote the current directory, neither to shell commands nor in system calls. It did on some older systems, but not on POSIX-compliant systems. Occasionally you'll find a program which uses the current directory when you pass an empty string and the program expects a directory name. This is sometimes deliberate, and ...


0

If the files are in the current directory you can just use ls: $ ls *.sh If you want the files in subdirectories also and just need the filename you could do something like: $ find . -name '*.h' -exec basename {} \; There are commands that will get the absence of a string as the current directory, but basically because they will get the current ...


12

A long time ago (in 7th edition, 32V, 4.2BSD, 4.3BSD), at the system-call level a zero-length pathname denoted the current working directory (when used for lookup; it was disallowed when trying to create or delete a file or directory). In System III, it was an error to use a zero-length pathname under all circumstances, and the POSIX standard has this to say ...


0

There are various tricks you can use to get find's output without the leading ./: Use find's -printf option and tell it to only print %f. See man find: %f                     File's name with any leading directories removed (only the last element). ...


2

I cannot think of any example where the empty string denotes the current directory .. You may be thinking of invocations like ls, but that is because ls assumes the current directory if no parameter is given, and in fact it won't take the empty string: ulmi@silberfisch:~$ ls "" ls: cannot access : No such file or directory


4

You can use: find * -name "*.h" Note that files in the current directory whose name starts with . will be omitted, and files whose name starts with - will be interpreted as options by find and cause havoc, so this is not a general equivalent to find . …. The absence of of a string ending in "/" as part of a file name implies the current directory, but ...


0

Use zsh and type what comes next. ZSH supports fuzzy auto complete and can deal with it. (Its especially nice with the OH-MY-ZSH plugin.)


5

Use find ... -print0 | while IFS= read -d '' construct: find ${POLLDIR} -type f -mmin +1 -print0 | while IFS= read -r -d '' -r sendfile; do echo "${sendfile}" ls -l "${sendfile}" and-so-on if success_above then mv "${sendfile}" "${donedir}/." fi done The -d '' sets the end of line character to \0 which is what separates each file found by ...


1

I don't use fish, but the documentation says that you can enter a Unicode character by prefixing its hex character code with \u (for 16-bit characters) or \U (for 32-bit characters). I think the code for ♫ is 491eb, so you could do: mv \U000491ebabc.mp3 abc.mp3 to rename ♫abc.mp3. Note that you need the leading zeroes, otherwise abc at the end will be ...


4

Rename symlinks One approach to handle file names with special characters - as first characters or elsewhere in the filename is to rename to simpler names. This can be used even if you need to keep the original filenames: Rename a copy of the filenames. That can be done by copying the files, but also by creating symlinks or hardlinks to the files, and ...


0

You didn’t say whether you want to keep these problematic filenames.  One solution might be to “fix” the problem once and for all by renaming (some or all of) your files to names that you can type by running this script: #!/bin/sh for old in * do printf "%s ...? " "$old" if read new && [ "$new" != "" ] then mv -i ...


6

ls has some switches (like --quote-name, --escape, --literal) for dealing with unprintable characters, but in this case it seems the character is "printable" but not "typeable" (at least on my keyboard!), so none of these switches seem to help. Therefore, as a general "brute force" approach to get rid of files with any characters in their names, you can do ...


4

The simplest that occurs to me is ls [^a-zA-Z0-9]* and it does the trick for me, but terdon's answer is better in bringing attention to the extglob shell option or even a shell-independent approach.


5

A similar approach would be to list all files that don't begin with "normal" characters. In bash you can do this with $ shopt -s extglob $ ls !([[:alpha:]]*) However, that does not seem to be available to fish, so you could use find instead: $ find . -type f -not -name '[[:alpha:]]*'


33

If the first character of file name is printable but neither alphanumeric nor whitespace you can use [[:punct:]] glob operator: $ ls *.txt f1.txt f2.txt ♫abc.txt $ ls [[:punct:]]*.txt ♫abc.txt


2

Google it. There isn't really a better way. It could be that some other software by the same name exists but no distribution has gotten around to packaging it yet. And even that isn't fully reliable: someone else could be doing the same thing right this minute and conclude that the name is available just as you do. You can check the package lists of major ...


1

If pick outputs of filename per line, you can set IFS to contain a newline only. Eg (in bash): saved_ifs=$IFS IFS=$'\n' for i in $(pick .??*) ; do ... ; done IFS=$saved_ifs This will allow your filenames to contain spaces and tabs, of course if they contain newlines there will still be a problem. You may also want to consider disabling globbing if there ...


0

find -name "* *" -type f -exec rename 's/ /_/g' {} + Replace the spaces in your filenames with "_". Then use pick. Rationale: Spaces in file names are typically considered a non-standard file naming convention. Successful I.T. is about doing things the same way every time, reminiscent of Sun Tzu's art of war: pick your battles carefully.


4

Try this: for folder in $(date +"%Y%m%d")*; do if [[ -d "$folder" ]]; then echo "Entering $folder" cd "$folder" echo "$PWD" cd .. fi done


0

Linux has always allowed any byte other than / and null in file names, like most other Unix variants (including the original). To change that, you would need to modify the filesystem code in the kernel. I'm not aware of any existing patch to do that. There isn't even a standard error code for attempts to create a file name that isn't supported, only ...


1

This is not possible. Please also explain what do you mean by "Most recent versions of most Linux distros": as far as I know, spaces are supported since the very first version of UNIX System V filesystem made in 1974.


1

Why not? Just give the relative path. In your case, it should be ../../Public-A/DIR-A/aaa.php There is no "sidewise" or other limits to relative paths.


-1

If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| \.[^/|'.].*" If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems. I came up ...


0

/vol/examples/tutorial/science.txt is an absolute path. When a path begins with / (slash), it starts from the root directory. If you want the path to start at the current directory (relative path), it must not start with a slash. joostin@ubuntu:~$ cd unixstuff joostin@ubuntu:~/unixstuff$ cp vol/examples/tutorial/science.txt .



Top 50 recent answers are included