0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

私的コマンドチートシート

Last updated at Posted at 2025-04-29

コマンドチートシート

シンボリックリンクを通す

sudo ln -s /path/to/target /path/to/wanna/to/place

特定の階層以下のファイルのパスと内容を表示

find path/to/directory/ -type f -exec sh -c 'echo "==== {} ===="; cat {}' \;

curl

静的ファイルからヘッダ情報取得

curl -I https://example.com/path/to/sample.txt

find

再帰的にfindでディレクトリに対してchmod 755

sudo find /mc -type d -exec chmod 755 {} \;

すべてのファイルをチェック

find /path/to/directory -type f -exec file -i {} \;

階層1

find /path/to/directory -maxdepth 1 -type f -exec file -i {} \;

その階層のすべてのファイルに対し、実行

(ここでは、cpコマンドでbackupディレクトリへ)

find . -maxdepth 1 -type f -exec cp {} ./backup \;

ファイルの文字コードを出力

file -i /path/to/file

zip

zip -r FILENAME.zip FILE_DIR

除外

zip -r sample.zip sample/ -x "sample/libraries/*" "sample/log/*"

一個前のコマンドを出力

history | tail -n 1
# or
fc -ln -1

一個前のコマンドを再実行

!!

acl

mcユーザーに対して、/mc/serverフォルダおよびそのサブディレクトリとファイルに対する全アクセス権限を再帰的に付与する。

sudo setfacl -R -m u:mc:rwx /mc/server

mcユーザーに対するデフォルトACLを設定し、将来的に新しく作成されるファイルやディレクトリにも同じ権限が適用されるようにする。

sudo setfacl -dR -m u:mc:rwx /mc/server

tail

sudo tail -f /var/log/nginx/access.log

tree

tree -I "*.html|*.png|*.jpg"

tree -I venv/
tree -I node_modules/

github

特定のコミットを削除するには

git reset --hard HEAD~1
git revert <commit-id>
git rebase --continue

リモートURLをSSHに変更

まず、鍵を生成し、それをデプロイ

git config --global user.name ""
git config --global user.email ""
ssh -T git@github.com
git remote set-url origin git@github.com:<user>/<repo>.git

リモートURLをHTTPSに変更

git remote set-url origin https://github.com/<user>/<repo>.git

特定のブランチ名を指定してクローン

git clone -b <branch-name> <clone-url>

access-tokenをローカルに設定

リポジトリのHTTPS URLにアクセストークンを埋め込む。
元のHTTPS URLhttps://github.com/username/repository.gitの場合、以下の形式に変更する。
https://your_access_token@github.com/username/repository.git
your_access_tokenは、生成したアクセストークンに置き換えよう。

最後に、リモートURLを変更

git remote set-url origin https://your_access_token@github.com/username/repository.git

タグを作ってプッシュ

git tag -a v1.0 -m 'version 1.0'
git push origin v1.0

リモートで使ったタグを削除するとき、ローカルには残っているため、それを削除する

git tag -d <tag-name>

新規リモートに対して特定ブランチへのプッシュまで

git remote add origin https://github.com/<user>/<repo>.git

git status
git add .
git commit -m "first commit"
git checkout -b scala

新規リモートをWEBで作った後、プッシュまで

git init
echo "# updater" >> README.md
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/<user>/<repo>.git
git push -u origin master

remote-urlを確認するには

git remote -v

git configのリセット

git config --global --unset credential.helper
git config --global --unset credential.credentialStore

submoduleを一括インポートする

git submodule update --init --recursive

リモートブランチ名をリネームしたときにローカルでやること

例えば、sampleブランチをmasterブランチに変更したとする。

ローカルのsampleブランチをmasterにリネームする

git branch -m sample master

リモート追跡ブランチを更新する

git remote set-head origin -a

追跡ブランチを設定する

git branch --set-upstream-to=origin/master master

ブランチを切り替える

現在どのブランチにいるかを確認
git status
ローカルでmasterブランチのものをdevブランチに変更してプッシュする

ローカルにdevブランチを作成し、masterブランチの内容を引き継ぎ、そのブランチに切り替えることができる。

git checkout -b dev master

これを実行した後は、以下を実行し、devの左に*がついていることを確認しよう。

git branch

初めてプッシュする場合は、以下を実行しよう。

git push -u origin dev

レポジトリ名を変更時にローカルですること

リモートレポジトリURLを新しいものにする
git remote set-url origin <new-repo-url>

リモートを追加

git remote add origin https://github.com/<user>/<repo>.git
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?