Hot answers tagged

67

Short answer mkdir takes multiple arguments, simply run mkdir dir_1 dir_2


55

You can use lists to create directories and it can get pretty wild. Same examples to get people thinking about it: mkdir sa{1..50} mkdir -p sa{1..50}/sax{1..50} mkdir {a-z}12345 mkdir {1,2,3} mkdir test{01..10} mkdir -p `date '+%y%m%d'`/{1,2,3} mkdir -p $USER/{1,2,3} 50 directories from sa1 through sa50 same but each of the directories will hold 50 ...


10

I'll try to give you some hints so you can solve your HW yourself. Follow this steps: read the manual of file by executing man file. Then try it out by file somefile and see what happens Try to run file on different file types By now you should be able to understand how to find out if some file is a jpeg image or not. now read the manual for find (or use ...


9

Re-reading your question again I think I understand what you're asking. Whatever you type in the command prompt is interpreted by an underlying shell (if you didn't change it, Bash). There is a number of steps Bash goes through before actually running the command: When the shell reads input, it proceeds through a sequence of operations. If the input ...


6

You can print all non-ASCII lines of a file using the following Python 3 script: #! /usr/bin/env python3 import sys import argparse argparser = argparse.ArgumentParser(description="Show all lines of a FILE " "containing characters that don't match the selected ENCODING.") argparser.add_argument("files", action="store", nargs="+", ...


6

Something like this? (thanks to muru for the printf tip) printf '%s' 'foo,bar,baz' | xargs -d, mkdir $ ls $ printf '%s' 'foo,bar,baz' | xargs -d, mkdir $ ls bar baz foo $ You can wrap it into a function for ease of use: function mkdir_cs { printf '%s' "$1" | xargs -d, mkdir } $ ls $ mkdir_cs 'foo,bar,baz' $ ls bar baz foo $


5

This snippet: # Add git branch if its present to PS1 parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' else ...


5

So you want comma separated list of directory names ? That can be done. Shell + coreutils Since everybody is posting oneliners, here's mine as well ( mkdir + parameter substitution plus + shell redirection ). DIR:/testdir skolodya@ubuntu:$ ls DIR:/testdir skolodya@ubuntu:$ mkdir $( tr '[,\n]' ' ' < /home/xieerqi/dirList.txt ) ...


5

When you run sh rBackup.sh the script rBackup.sh is being run by sh (dash) which does not support brace expansion. On the other hand, when you do ./rBackup.sh then the #!/bin/bash first line specifies the exact interpreter to use. It happens that bash supports brace expansion. If you don't include a valid executable in the shebang line, you are ...


4

Keep in mind that sh actually calls dash, which is limited compared to, say, Bash. As was observed by @Serg in a comment on the question, the curly braces are being interpreted as inputs to dash, possibly, which is why it won't work. This is why it's failing - Dash doesn't do Brace Expansion. You're probably expecting the system to use Bash style ...


4

cp does not support any wildcards by itself. Expansion of wildcards and patterns is done by the shell, which is bash by default. In any case, character classes are to be specified within [] - that excludes the [] already surrounding them. Like so: cp Downloads/[[:alnum:]] test/ However, [[:alnum:]] will only match a single alphanumeric character. To ...


4

Using shutter and wmctrl, an edited version of this script does pretty much exactly what you describe: it takes a screenshot of the area, a specific window covers on your screen, no matter if and how the window is (partially) below other windows. The marge around the window, to be included in the screenshot, is arbitrary; set it to zero if you like. In ...


4

If you want to look for non-ASCII characters, perhaps you should invert the search to exclude ASCII characters: grep -Pn '[^\x00-\x7F]' For example: $ curl https://help.ubuntu.com/16.04/installation-guide/amd64/install.en.txt -s | grep -nP '[^\x00-\x7F]' | head 9:Appendix F, GNU General Public License. 14:(codename "‘Xenial Xerus’"), for the 64-bit PC ...


3

This Perl command mostly replaces that grep command (the thing missing being the colors): perl -ne '/[\x80-\xFF]/&&print($ARGV."($.):\t^".$_)' *.xml n: causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk: LINE: while (<>) { ... # your ...


3

The shell processes the parameters. That will prevent the shell from doing it: ./myFile '&' So, the program will get & as a parameter. Other example: ./myFile * It'll expand the star into a whole list of the parameters - the file names of files in current directory.


3

Using Perl: perl -F'\|\|\|' -lane '$, = "\t"; @f = split(/;|\|/, $F[1]); shift(@f); splice(@f, 5); print(@f)' file -F'\|\|\|': sets the input field separator to |||; -l: enables automatic line-ending processing. It has two separate effects. First, it automatically chomps $/ (the input record separator) when used with -n or -p. Second, it assigns $\ (the ...


3

Make a list of the names for your desired directories using line breaks instead of commas as a separator. Save that list. mkdir `cat list` You should now have all the directories named in your list.


3

You can re-label file systems with Gnome Disks: If you really want to use the command line, the command depends on the affected file system type. For ext2/3/4 it's sudo e2label <DEVICE> <NEW_LABEL> In a similar fashion there are fatlabel, exfatlabel, ntfslabel, btrfs filesystem label, swaplabel for other file system types with the same ...


3

The way to find the problem: run.sh is a script. So do a more run.sh to see what is on the line number is shows in the error. The line will start with a command (java most likely). Do a java --version. If this errors out you did not install "java" and the program depends on it. sudo apt-get install openjdk-8-jre would install Open JDK 8 and make the ...


2

Yes! Linux has killall. Try killall firefox. But my favorite is command line task manager htop - run that, press F5 for process tree view and kill necessary process. Well, actually process killing is bad. You have to have pretty good reason to do that. Try to find source of problem.


2

Using Perl: perl -pe 's/\bweb\K[0-9]+\b/$&+1/ge' file -p: causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed: LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; } -e: may be ...


2

AWK can search and replace text as well, so there is no need to use grep or sed. The code bellow extracts substring from second column (webN), increments N, and substitutes second field with webN+1 $ cat testInput.txt project web0 other project web1 $ awk '/web/{ ...


2

EDIT Since you've asked how to check if a process is running or not when you know its name , then it's a simple pgrep operation. Alternatively, one could use ps and specify state options for formating $ ps --no-headers -C firefox -o args,state /usr/lib/firefox/firefox R State code is on the right. From man ps you can know their ...


2

If you want to live track the processes you can have the famous command: top but you want it by filename so you will need to add a parameter as: top -c


2

One possible solution could be this: use find which recursively lists regular files (-type f), and performs file command upon each one of them. Redirect output to grep to filter out filetypes. However here, I would like to do something more fun than that; more awkward , but more fun. $ find . -maxdepth 1 -type f -printf "%f\t" -exec hexdump -n8 {} \; | ...


2

First of all i want to thank @incBrain and @Serg for not answering my question directly which helped me understand a lot of new things :). My task was finding a specific .jpg file that has it's extension removed, the first thing I though of is .jpg magic byte which was JFIF, and with @incBrain Instructions I was able to build this command find / -exec ...


2

Nothing's wrong with tee. Python buffers output if it detects it's not writing to a TTY. See this Unix & Linux post. Use sys.stdout.flush() to force flushing the buffer.


2

tacmd listsystems | grep -i $i | awk '{print $1}' >> offline.lst The >> operator tells bash to append output to a file.


2

Let's use sed: sed -r 's/.*\|\|\|;(CSQ[^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|.*/\1\t\2\t\3\t\4\t\5/' file.txt python is not fast at manipulating very large file, this would be much faster than python. Example: % cat file.txt 2 41620 . T G 100 PASS ...


2

This should work for you: cut -d"|" -f4,5,6,7,8 filename.txt | sed 's/;//g' | sed 's/|/\t/g' Example: $ echo "2 41620 . T G 100 PASS ...



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