Tag Info

New answers tagged

2

You might see some information from here. Generally, a file descriptor is an index for an entry in a kernel-resident data structure containing the details of all open files. In POSIX, this data structure is called a file descriptor table, and each process has its own file descriptor table. The user application passes the abstract key to the kernel through a ...


3

A FILE structure in C is typically called the file handle and is a bit of abstraction around a file descriptor: The data type FILE is a structure that contains information about a file or specified data stream. It includes such information as a file descriptor, current position, status flags, and more. It is most often used as a pointer to a ...


3

You need to quote file name: rm 'my file' my_file or escape space character: rm my\ file my_file


3

You have to quote or escape the filename. In Bash (the default shell in most distros), you can either use quote marks to enclose the entire name, or a backslash to escape the one space. rm "my file" rm my\ file


1

With zsh: print -r -- **/*.csv(D:a:q) Note that some characters (like newline, tab or non-printable ones) are rendered with the $'...' notation which may be a problem for you. Another approach is: print -r -- *.csv(e/'REPLY=${(qq)REPLY:a}'/) Where all the file paths are single-quoted.


4

For passing file paths as arguments to a command, find does this on its own with its -exec option without any xargs trickery: find /home/user -name '*.csv' -exec yourcommand '{}' + That will find every file called *.csv in /home/user and then execute yourcommand /home/user/a\ b.csv /home/user/my\ dir/c\ d\$2.csv ... with all of the found files as ...


3

In a POSIX shell: $ x='/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt' $ printf "/%s\n" "${x#/*/}" /VPfig/Amer/AR4/Celtel/files/COM.txt Explanation The parameter expansion ${x#/*/} removes the leading component of the path with the two /s enclosing it and the printf tacks a leading / back on.


2

The simplest way would be to remove the shortest string of non-/ characters from the beginning of the string. In most regular expression languages, [ ] os a character class that matches anything within the brackets. [abc] will match either a or b or c. [^ ] is a negated character class, matching anything except the characters in it. So, [^/]* will match ...


5

Try: echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed 's|^/[^/]*||' which gave me: /VPfig/Amer/AR4/Celtel/files/COM.txt It looks for the first / followed by as many non-/s as possible, then replaces them with an empty string.


2

My suggestion: GLOBIGNORE=$(echo */) # create list of directories with globbing GLOBIGNORE=${GLOBIGNORE//:/\\:} # escape possible ":" with "\" to allow # the separator ":" in directory names GLOBIGNORE=${GLOBIGNORE//\/ /:} # replace "/ " with separator ":" GLOBIGNORE=${GLOBIGNORE%/} # remove trailing "/" ...


2

This should really be a comment, but I don't have enough points. That said - I'm not sure which of the 2 options to you want to achieve - bash globing that excludes based on filesystem attributes, or a way to display only files in a directory? If the first, I'm not sure that's possible. Globing just expands, and filenames are a base in any directory - bash ...


5

The reason */ matches directories is that the final / restricts matches to directories. This effect is only triggered when the / is after a pattern, you can't use / inside parentheses in !(*/). There's no feature built into bash to do what you want. You can make a loop over all files and build an array. non_directories=() for x in *; do [ -d "$x" ] || ...


6

find . -maxdepth 1 ! -type d Details: -maxdepth 1 restricts the search to the current directory ! -type d eliminates directories


3

Sort of long winded, but: for f in *; do if [ ! -d "$f" ]; then echo "$f"; fi; done -d is a file test operator to check if the argument is a directory. The above could also be shortened to for f in *; do [ ! -d "$f" ] && echo "$f"; done


1

If rz doesn't have the sense to somehow return the filename it receives, then a crude hack is to just get the latest modified (ctime-wise) file in the directory and hope no other files were created concurrently: rz && export FILE_RECEIVED=`ls -t --time=ctime | head -1`


2

Place the single quote within double quotes, as follows: sftp> put /path/Dr"'"\ A.tif It would also handle most other special characters as well. If you want to have a single double-quote, then quote the single double-quote within double single-quotes :-) : sftp> put /path/Dr'"'\ A.tif Alternatively, you can escape the single or double quotes: ...


1

The tilde when used alone in the context of ls ~ will list your home dir as ~ is a shortcut to your home dir. If you did ls ~brown then you will list the contents of brown's home dir. VIM, unless told otherwise, will create a back-up copy of a changed file: myFile myFile~. This behavior is good as it creates a back-up but if you don't want it, add to you ...


4

Just use a loop in the shell: for x in * ; do mv -- "$x" "$((i=i+1)).jpg" ; done We look at each file in the current directory one at a time, calling it x, and then move it to $i.jpg, where we increment $i by one each time. $((...)) is arithmetic expansion, and assignments return the value assigned, so this both modifies i and returns the new number each ...


0

Assuming that there is only ever one file in the directory: file_name=`ls wip_folder` log_file="${log_file}.log"


0

I think this bash function, pathStr(), will do what you are looking for. It doesn't require awk, sed, grep, perl or expr. It uses only bash builtins so it's quite fast. I've also included the dependent argsNumber and isOption functions but their functionalities could be easily incorporated into pathStr. The dependent function ifHelpShow is not included as ...


34

Either quote it: rm -i '~' rm -i "~" rm -i \~ Or reference it by a path, instead of just a basename: rm -i ./~ rm -i /path/to/~ Note that, despite being a funny-looking single character name, this is conceptually no different than if you had created a file named SOME$PATH by doing touch 'SOME$PATH' And tried to remove it by doing: rm -i SOME$PATH ...



Top 50 recent answers are included