Hot answers tagged

15

You could change your default shell to bash by typing in the following line: chsh -s /bin/bash You will probably need to log out and log back in for the settings to take effect. Then if you wanted to run fish, it would just be the command fish at a bash prompt. More information can be found at https://wiki.ubuntu.com/ChangingShells


8

The script below should do the job: #!/usr/bin/env python3 import random import os import subprocess import shutil # set the desired number of folders to pick below n_selection = 5 # set the name of the flash drive below flashdr = "Lexar" # set the source directory (with media folders) below sourcedr = "/path/to/mediafiles" # --- try: targetdr = ...


5

you could use find and shuf: #!/bin/bash SOURCE="path/to/source" DESTINATION="path/to/destination" COUNT=25 rm -r "${DESTINATION}/"* find "$SOURCE" -mindepth 2 -maxdepth 2 -type d|shuf -n $COUNT|xargs -d'\n' -I{} cp -r "{}" "$DESTINATION"


4

What did you try? You could define a function in your ~/.bashrc, thusly: function showmem() { free -m | tr -s ' ' '\t' | grep Mem: | cut -f3 } and then set Bash's PROMPT_COMMAND to that function PROMPT_COMMAND=showmem Remember to source ~/.bashrc whenever you change ~/.bashrc.


3

Firstly using the gcc switch -c you are telling the compiler to only compile and not link which doesn't produce an executable binary to get an executable binary you need to not use this switch. The correct command would be: gcc cents.c However since this command does not specify the output file name the default name a.out will be used for the binary so ...


3

Please consult the manual page of ls(1)! The ls command takes it's arguments on the command line not on standard input (i. e. file descriptor 0). When you run <SOME_COMMAND> | ls [OPTIONS...] you instruct the command interpreter to create a pipe (|) from the the standard output of the left command to the standard input of the right command (here: ...


3

While similar, the wildcard patterns that you’re referring to are not regular expressions; they are glob patterns and in this context, shell patterns. They are expanded by the shell itself – not by commands such as ls, cp, etc. Just to clarify, these commands are not actually “bash utilities”; they are programs that can be executed by any shell. When a ...


2

You could do this using the following bash script. #!/bin/bash for file in $(ls) do date=${file:0:2} month=${file:2:2} year=${file:4:4} sequence=${file:8:4} extension=${file: -3} mv $file $year\-$month\-$date\-$sequence.$extension done echo all files have been renamed In order to use this script, open a terminal and type touch ...


2

You should be able to do that using capture groups with the perl-based rename command e.g. at its simplest rename -vn -- 's/^(\d{2})(\d{2})(\d{4})/$3-$2-$1/' *.jpg (Note: the -n is a dry-run flag: it won't actually change anything unless you remove that.)


2

Here ./testzenity: ligne 10: ls-al : commande introuvable it saying. No command like ls-la. it is ls -la. Hope it helps


2

You don't specify in your question if it is a requirement to preserve the directory structure in the copy or if you just need a copy of the files. To simply copy all the files not named *.data you could use this: find . -type f ! -name '*.data' | xargs cp -t ../destination_dir/ On the other hand if you want to preserve the directory structure you could ...


2

In fact what you posted there is called a fork bomb, because it does exactly that it is a bash function which calls itself twice and so on. You can replace the : with a name if you want so it becomes more obvious: fu{ fu | fu & }; fu So fucalls itself piping its output through itself again and this way fills up your processor with requests. It is ...


2

Fortunately, Dropbox recently expanded their CLI capabilities to include sharelinks etc. To integrate Dropbox into Thunar do the following: Initial Setup Create a ~/bin directory in your home folder if not already created. Download the Dropbox python script. Rename it as just dropbox. (The extension is not needed.) Make it executable chmod +x ...


1

Instead of setting PROMPT_COMMAND, as @waltinator suggested, you could embed the command into the actual prompt with process substitution: PS1='\u@\h\n$(showmem) \$ ' This PS1 is based on the one you mentioned in a comment, and uses the function that @waltinator made.


1

You can use process substitution, so that use would look like: use() { . <(. ./hello_world.sh; declare -f "$@") } Side note: declare is not POSIX, /bin/sh may not support it, so use.sh shouldn't have /bin/sh in the shebang. (Not that it matters much, since use.sh is sourced instead of executed.)


1

The bash shell supports the syntax ${s:$i:1} to refer to the ith character of string s (strictly speaking, a substring of length 1 starting at position $i), so you can do something like Num=13427598 for ((i=0;i<${#Num};i++)); do Gen=$(shuf -i 0-9 -n 1) if (($Gen == ${Num:$i:1})) then echo "$Gen matches at position $i" else echo ...


1

I'm glad it's OK to answer my own question because I wanted to chronicle my turmoil in hopes that others following behind in my trail of tears could be spared by searching some key words. Eventually, I discovered the right answer, but it was posted to the wrong question. A couple points of clarity: The manual isn't referring to a literal list as in a ...


1

There is no stdout in your example: wrapping a shell function definition in a script file and then calling the script does not execute the function. You need to either source the script so that the function becomes available in the current shell . Sourced/getFileSystemInfo getFileSystemInfo $(pwd) fstype,source or modify the script so that it calls the ...


1

One simple way would be to set an array with the four values you want to cycle through, and then use the % (modulo) operator in your for loop to determine which of the four values to assign to arr[$a] For example: #!/bin/bash values=("apple", "banana", "orange", "grape") ##################################### for((a=0;a<=100;a++)) do ...


1

I made a script with Python: The script, at GitHub Gist. (Download) Usage: python3 RandomCopier.py [source folder] [destination folder] [number to copy] The copy method: NOTE: It will not copy any files directly in the source folder, only those in sub-folders of it. Say, the source folder, src is: src |- a | |- file_a | |- file_a_2 | |- b | |- ...


1

You can use cpio's pass-through mode with the -d option for that job: cpio -p -d DESTINATION < FILELIST This will create a copy of the whole directory structure specified in FILELIST (relative to the current working directory) underneath DESTINATION. With your example you will then have ...


1

As commented above, this can be fixed with root->user ownership changes. Initial permissions may be from -rw-r--r-- or any other variation and root ownership. In my case I only had .bash_history owned by root but it is all of .bash_* that must be owned by user.



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